-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81dc118
commit 38ab4ef
Showing
4 changed files
with
42 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SymmetricKey.swift | ||
// based on the Vapor/open-crypto project which tries to replicate the CryptoKit framework interface | ||
// written by AdamFowler 2020/01/30 | ||
import protocol Foundation.ContiguousBytes | ||
|
||
/// Symmetric key object | ||
public struct SymmetricKey: ContiguousBytes { | ||
let bytes: [UInt8] | ||
|
||
public var bitCount: Int { | ||
return self.bytes.count * 8 | ||
} | ||
|
||
public init<D>(data: D) where D : ContiguousBytes { | ||
let bytes = data.withUnsafeBytes { buffer in | ||
return [UInt8](buffer) | ||
} | ||
self.init(bytes: bytes) | ||
} | ||
|
||
public init(bytes: [UInt8]) { | ||
self.bytes = bytes | ||
} | ||
|
||
public func withUnsafeBytes<R>(_ body: (UnsafeRawBufferPointer) throws -> R) rethrows -> R { | ||
return try self.bytes.withUnsafeBytes(body) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters