File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed
Sources/CryptomatorCryptoLib
Tests/CryptomatorCryptoLibTests Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff 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)
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments