Use SecKeyGetBlockSize instead of kSecAttrKeySizeInBits (#198)

This commit is contained in:
David Nadoba authored and GitHub committed 2023-08-17 06:53:44 -07:00
1 parent 710deacf79
commit 953b34a601
2 files changed
+6 -8

No files matched your search

+4 -4
View File
@@ -54,7 +54,7 @@ extension _RSA.Signing {
public init(pemRepresentation: String) throws {
self.backing = try BackingPublicKey(pemRepresentation: pemRepresentation)
if self.keySizeInBits < 1024 || self.keySizeInBits % 8 != 0 {
guard self.keySizeInBits >= 1024 else {
throw CryptoKitError.incorrectParameterSize
}
}
@@ -66,7 +66,7 @@ extension _RSA.Signing {
public init<Bytes: DataProtocol>(derRepresentation: Bytes) throws {
self.backing = try BackingPublicKey(derRepresentation: derRepresentation)
if self.keySizeInBits < 1024 || self.keySizeInBits % 8 != 0 {
guard self.keySizeInBits >= 1024 else {
throw CryptoKitError.incorrectParameterSize
}
}
@@ -108,7 +108,7 @@ extension _RSA.Signing {
public init(pemRepresentation: String) throws {
self.backing = try BackingPrivateKey(pemRepresentation: pemRepresentation)
if self.keySizeInBits < 1024 || self.keySizeInBits % 8 != 0 {
guard self.keySizeInBits >= 1024 else {
throw CryptoKitError.incorrectParameterSize
}
}
@@ -120,7 +120,7 @@ extension _RSA.Signing {
public init<Bytes: DataProtocol>(derRepresentation: Bytes) throws {
self.backing = try BackingPrivateKey(derRepresentation: derRepresentation)
if self.keySizeInBits < 1024 || self.keySizeInBits % 8 != 0 {
guard self.keySizeInBits >= 1024 else {
throw CryptoKitError.incorrectParameterSize
}
}
+2 -4
View File
@@ -61,8 +61,7 @@ internal struct SecurityRSAPublicKey {
}
var keySizeInBits: Int {
let attributes = SecKeyCopyAttributes(self.backing)! as NSDictionary
return (attributes[kSecAttrKeySizeInBits]! as! NSNumber).intValue
SecKeyGetBlockSize(self.backing) * 8
}
fileprivate init(_ backing: SecKey) {
@@ -146,8 +145,7 @@ internal struct SecurityRSAPrivateKey {
}
var keySizeInBits: Int {
let attributes = SecKeyCopyAttributes(self.backing)! as NSDictionary
return (attributes[kSecAttrKeySizeInBits]! as! NSNumber).intValue
SecKeyGetBlockSize(self.backing) * 8
}
var publicKey: SecurityRSAPublicKey {