File tree Expand file tree Collapse file tree 3 files changed +37
-35
lines changed Expand file tree Collapse file tree 3 files changed +37
-35
lines changed Original file line number Diff line number Diff line change @@ -11,14 +11,14 @@ let dependencies = [
11
11
Package . Dependency. package ( url: " https://github.com/kylef-archive/CommonCrypto.git " , from: " 1.0.0 " ) ,
12
12
]
13
13
#endif
14
- let excludes = [ " HMAC/HMACCryptoSwift .swift " ]
14
+ let excludes = [ " HMAC/HMACCrypto .swift " ]
15
15
let targetDependencies : [ Target . Dependency ] = [ ]
16
16
#else
17
17
let dependencies = [
18
- Package . Dependency. package ( url: " https://github.com/krzyzanowskim/CryptoSwift.git " , from: " 0.10.0 " ) ,
18
+ Package . Dependency. package ( url: " https://github.com/apple/swift-crypto " , from: " 1.1.3 " ) ,
19
19
]
20
20
let excludes = [ " HMAC/HMACCommonCrypto.swift " ]
21
- let targetDependencies : [ Target . Dependency ] = [ " CryptoSwift " ]
21
+ let targetDependencies : [ Target . Dependency ] = [ " Crypto " ]
22
22
#endif
23
23
24
24
Original file line number Diff line number Diff line change
1
+ import Foundation
2
+ import Crypto
3
+
4
+
5
+ extension HMACAlgorithm : SignAlgorithm , VerifyAlgorithm {
6
+ var symmetricKey : SymmetricKey {
7
+ return SymmetricKey ( data: key)
8
+ }
9
+
10
+ public func sign( _ message: Data ) -> Data {
11
+ switch hash {
12
+ case . sha256:
13
+ let code = HMAC< SHA256> . authenticationCode( for: message, using: symmetricKey)
14
+ return Data ( code)
15
+ case . sha384:
16
+ let code = HMAC< SHA384> . authenticationCode( for: message, using: symmetricKey)
17
+ return Data ( code)
18
+ case . sha512:
19
+ let code = HMAC< SHA512> . authenticationCode( for: message, using: symmetricKey)
20
+ return Data ( code)
21
+ }
22
+ }
23
+
24
+ public func verify( _ message: Data , signature: Data ) -> Bool {
25
+ switch hash {
26
+ case . sha256:
27
+ return HMAC< SHA256> . isValidAuthenticationCode( signature, authenticating: message, using: symmetricKey)
28
+ case . sha384:
29
+ return HMAC< SHA384> . isValidAuthenticationCode( signature, authenticating: message, using: symmetricKey)
30
+ case . sha512:
31
+ return HMAC< SHA512> . isValidAuthenticationCode( signature, authenticating: message, using: symmetricKey)
32
+ }
33
+ }
34
+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments