فهرست منبع

Remove key length check on HMACSHA256

maxep 5 سال پیش
والد
کامیت
67d122cad5
1فایلهای تغییر یافته به همراه3 افزوده شده و 6 حذف شده
  1. 3 6
      Sources/Crypto/Hash.swift

+ 3 - 6
Sources/Crypto/Hash.swift

@@ -90,8 +90,7 @@ public final class HMACSHA256 {
         return out
     }
 
-    public init(key: Bytes) throws {
-        guard key.lenght == crypto_auth_hmacsha256_KEYBYTES else { throw CryptoError.invalidKey }
+    public init(key: Bytes) {
         state = crypto_auth_hmacsha256_state()
         crypto_auth_hmacsha256_init(&state, key.rawValue, lenght(key))
     }
@@ -100,12 +99,10 @@ public final class HMACSHA256 {
         crypto_auth_hmacsha256_update(&state, bytes.rawValue, lenght(bytes));
     }
 
-    public static func authenticate(_ bytes: Bytes, key: Bytes) throws -> Bytes {
-        let hmac = try HMACSHA256(key: key)
+    public static func authenticate(_ bytes: Bytes, key: Bytes) -> Bytes {
+        let hmac = HMACSHA256(key: key)
         hmac.update(bytes)
         return hmac.final
     }
 
 }
-
-