Skip to content

Commit

Permalink
Add additional hmac signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewBarba committed Feb 27, 2023
1 parent e6f914c commit 24fb415
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions Sources/Compute/Crypto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,22 @@ extension Crypto {
}

public static func code(for input: String, secret: String, using hash: Hash) -> Data {
let data = Data(input.utf8)
let key = SymmetricKey(data: Data(secret.utf8))
return code(for: Data(input.utf8), secret: Data(secret.utf8), using: hash)
}

public static func code(for input: Data, secret: Data, using hash: Hash) -> Data {
let key = SymmetricKey(data: secret)
return code(for: input, secret: key, using: hash)
}

public static func code(for input: Data, secret: SymmetricKey, using hash: Hash) -> Data {
switch hash {
case .sha256:
return HMAC<SHA256>.authenticationCode(for: data, using: key).data
return HMAC<SHA256>.authenticationCode(for: input, using: secret).data
case .sha384:
return HMAC<SHA384>.authenticationCode(for: data, using: key).data
return HMAC<SHA384>.authenticationCode(for: input, using: secret).data
case .sha512:
return HMAC<SHA512>.authenticationCode(for: data, using: key).data
return HMAC<SHA512>.authenticationCode(for: input, using: secret).data
}
}

Expand Down

0 comments on commit 24fb415

Please sign in to comment.