mirror of
https://github.com/bitwarden/ios.git
synced 2025-12-11 13:54:06 -06:00
28 lines
716 B
Swift
28 lines
716 B
Swift
import CryptoKit
|
|
import Foundation
|
|
|
|
class CryptoFunctionService {
|
|
static let shared: CryptoFunctionService = .init()
|
|
|
|
enum CryptoHashAlgorithm {
|
|
case Sha1
|
|
case Sha256
|
|
case Sha512
|
|
}
|
|
|
|
enum CryptoError: Error {
|
|
case AlgorithmNotImplemented
|
|
}
|
|
|
|
func hmac(_ data: Data, _ key: SymmetricKey, algorithm alg: CryptoHashAlgorithm) -> Data {
|
|
switch alg {
|
|
case .Sha1:
|
|
Data(HMAC<Insecure.SHA1>.authenticationCode(for: data, using: key))
|
|
case .Sha256:
|
|
Data(HMAC<SHA256>.authenticationCode(for: data, using: key))
|
|
case .Sha512:
|
|
Data(HMAC<SHA512>.authenticationCode(for: data, using: key))
|
|
}
|
|
}
|
|
}
|