소스 검색

SwiftFormat

Brandon Toms 3 년 전
부모
커밋
0ea13c82e0
2개의 변경된 파일35개의 추가작업 그리고 35개의 파일을 삭제
  1. 33 33
      Sources/CryptoSwift/RSA/RSA+Cipher.swift
  2. 2 2
      Sources/CryptoSwift/RSA/RSA+Signature.swift

+ 33 - 33
Sources/CryptoSwift/RSA/RSA+Cipher.swift

@@ -76,50 +76,50 @@ extension RSA {
     @inlinable
     internal func prepare(_ bytes: Array<UInt8>, blockSize: Int) throws -> Array<UInt8> {
       switch self {
-      case .unsafe:
-        return bytes
-      case .raw:
-        // We need at least 11 bytes of random padding in order to safely encrypt messages
-        guard blockSize >= bytes.count + 11 else { throw RSA.Error.invalidMessageLengthForEncryption }
-        return Array(repeating: 0x00, count: blockSize - bytes.count) + bytes
-      case .pksc1v15:
-        guard !bytes.isEmpty else { throw RSA.Error.invalidMessageLengthForEncryption }
-        // We need at least 11 bytes of random padding in order to safely encrypt messages
-        guard blockSize >= bytes.count + 11 else { throw RSA.Error.invalidMessageLengthForEncryption }
-        return Padding.eme_pkcs1v15.add(to: bytes, blockSize: blockSize)
+        case .unsafe:
+          return bytes
+        case .raw:
+          // We need at least 11 bytes of random padding in order to safely encrypt messages
+          guard blockSize >= bytes.count + 11 else { throw RSA.Error.invalidMessageLengthForEncryption }
+          return Array(repeating: 0x00, count: blockSize - bytes.count) + bytes
+        case .pksc1v15:
+          guard !bytes.isEmpty else { throw RSA.Error.invalidMessageLengthForEncryption }
+          // We need at least 11 bytes of random padding in order to safely encrypt messages
+          guard blockSize >= bytes.count + 11 else { throw RSA.Error.invalidMessageLengthForEncryption }
+          return Padding.eme_pkcs1v15.add(to: bytes, blockSize: blockSize)
       }
     }
-    
+
     @inlinable
-    internal func formatEncryptedBytes(_ bytes:Array<UInt8>, blockSize: Int) -> Array<UInt8> {
+    internal func formatEncryptedBytes(_ bytes: Array<UInt8>, blockSize: Int) -> Array<UInt8> {
       switch self {
-      case .unsafe:
-        return bytes
-      case .raw, .pksc1v15:
-        // Format the encrypted bytes before returning
-        var bytes = bytes
-        if bytes.isEmpty {
-          // Instead of returning an empty byte array, we return an array of zero's of length keySize bytes
-          // This functionality matches that of Apple's `Security` framework
-          return Array<UInt8>(repeating: 0, count: blockSize)
-        } else {
-          while bytes.count % 4 != 0 { bytes.insert(0x00, at: 0) }
+        case .unsafe:
           return bytes
-        }
+        case .raw, .pksc1v15:
+          // Format the encrypted bytes before returning
+          var bytes = bytes
+          if bytes.isEmpty {
+            // Instead of returning an empty byte array, we return an array of zero's of length keySize bytes
+            // This functionality matches that of Apple's `Security` framework
+            return Array<UInt8>(repeating: 0, count: blockSize)
+          } else {
+            while bytes.count % 4 != 0 { bytes.insert(0x00, at: 0) }
+            return bytes
+          }
       }
     }
 
     @inlinable
     internal func removePadding(_ bytes: Array<UInt8>, blockSize: Int) -> Array<UInt8> {
       switch self {
-      case .unsafe:
-        return bytes
-      case .raw:
-        return bytes
-      case .pksc1v15:
-        // Convert the Octet String into an Integer Primitive using the BigInteger `serialize` method
-        // (this effectively just prefixes the data with a 0x00 byte indicating that its a positive integer)
-        return Padding.eme_pkcs1v15.remove(from: [0x00] + bytes, blockSize: blockSize)
+        case .unsafe:
+          return bytes
+        case .raw:
+          return bytes
+        case .pksc1v15:
+          // Convert the Octet String into an Integer Primitive using the BigInteger `serialize` method
+          // (this effectively just prefixes the data with a 0x00 byte indicating that its a positive integer)
+          return Padding.eme_pkcs1v15.remove(from: [0x00] + bytes, blockSize: blockSize)
       }
     }
   }

+ 2 - 2
Sources/CryptoSwift/RSA/RSA+Signature.swift

@@ -13,7 +13,7 @@ extension RSA: Signature {
   public func sign(_ bytes: ArraySlice<UInt8>) throws -> Array<UInt8> {
     try self.sign(Array(bytes), variant: .message_pkcs1v15_SHA512_256)
   }
-  
+
   public func sign(_ bytes: Array<UInt8>, variant: SignatureVariant) throws -> Array<UInt8> {
     // Check for Private Exponent presence
     guard let d = d else {
@@ -32,7 +32,7 @@ extension RSA: Signature {
   public func verify(signature: ArraySlice<UInt8>, for expectedData: ArraySlice<UInt8>) throws -> Bool {
     try self.verify(signature: Array(signature), for: Array(expectedData), variant: .message_pkcs1v15_SHA512_256)
   }
-  
+
   /// https://datatracker.ietf.org/doc/html/rfc8017#section-8.2.2
   public func verify(signature: Array<UInt8>, for bytes: Array<UInt8>, variant: SignatureVariant = .message_pkcs1v15_SHA256) throws -> Bool {
     /// Step 1: Ensure the signature is the same length as the key's modulus