Skip to content

Commit 77eba0b

Browse files
committed
Added raw key (one param) initializer for Masterkey, adjusted access control of existing raw key (two params) initializer, which is just used in tests
1 parent 986fd4a commit 77eba0b

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Sources/CryptomatorCryptoLib/Masterkey.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,27 @@ public class Masterkey {
4444
return createFromRaw(aesMasterKey: aesMasterKey, macMasterKey: macMasterKey)
4545
}
4646

47+
/**
48+
Creates masterkey from raw bytes.
49+
50+
- Parameter rawKey: Key combination of `aesMasterKey` (used for encryption of file specific keys) and `macMasterKey` (used for file authentication).
51+
- Returns: New masterkey instance using the keys from the supplied raw bytes.
52+
*/
53+
public static func createFromRaw(rawKey: [UInt8]) -> Masterkey {
54+
assert(rawKey.count == 2 * kCCKeySizeAES256)
55+
let aesMasterkey = Array(rawKey[0 ..< kCCKeySizeAES256])
56+
let macMasterKey = Array(rawKey[kCCKeySizeAES256...])
57+
return createFromRaw(aesMasterKey: aesMasterkey, macMasterKey: macMasterKey)
58+
}
59+
4760
/**
4861
Creates masterkey from raw bytes.
4962

5063
- Parameter aesMasterKey: Key used for encryption of file specific keys.
5164
- Parameter macMasterKey: Key used for file authentication.
5265
- Returns: New masterkey instance using the keys from the supplied raw bytes.
5366
*/
54-
public static func createFromRaw(aesMasterKey: [UInt8], macMasterKey: [UInt8]) -> Masterkey {
67+
static func createFromRaw(aesMasterKey: [UInt8], macMasterKey: [UInt8]) -> Masterkey {
5568
assert(aesMasterKey.count == kCCKeySizeAES256)
5669
assert(macMasterKey.count == kCCKeySizeAES256)
5770
return Masterkey(aesMasterKey: aesMasterKey, macMasterKey: macMasterKey)

Tests/CryptomatorCryptoLibTests/MasterkeyTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class MasterkeyTests: XCTestCase {
1313
func testCreateFromRaw() throws {
1414
let aesMasterKey = [UInt8](repeating: 0x77, count: 32)
1515
let macMasterKey = [UInt8](repeating: 0x55, count: 32)
16-
let masterkey = Masterkey.createFromRaw(aesMasterKey: aesMasterKey, macMasterKey: macMasterKey)
16+
let masterkey = Masterkey.createFromRaw(rawKey: aesMasterKey + macMasterKey)
1717
XCTAssertEqual(aesMasterKey, masterkey.aesMasterKey)
1818
XCTAssertEqual(macMasterKey, masterkey.macMasterKey)
1919
}

0 commit comments

Comments
 (0)