Skip to content

Commit 0ea13c8

Browse files
committed
SwiftFormat
1 parent 3130d3f commit 0ea13c8

File tree

2 files changed

+35
-35
lines changed

2 files changed

+35
-35
lines changed

Sources/CryptoSwift/RSA/RSA+Cipher.swift

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -76,50 +76,50 @@ extension RSA {
7676
@inlinable
7777
internal func prepare(_ bytes: Array<UInt8>, blockSize: Int) throws -> Array<UInt8> {
7878
switch self {
79-
case .unsafe:
80-
return bytes
81-
case .raw:
82-
// We need at least 11 bytes of random padding in order to safely encrypt messages
83-
guard blockSize >= bytes.count + 11 else { throw RSA.Error.invalidMessageLengthForEncryption }
84-
return Array(repeating: 0x00, count: blockSize - bytes.count) + bytes
85-
case .pksc1v15:
86-
guard !bytes.isEmpty else { throw RSA.Error.invalidMessageLengthForEncryption }
87-
// We need at least 11 bytes of random padding in order to safely encrypt messages
88-
guard blockSize >= bytes.count + 11 else { throw RSA.Error.invalidMessageLengthForEncryption }
89-
return Padding.eme_pkcs1v15.add(to: bytes, blockSize: blockSize)
79+
case .unsafe:
80+
return bytes
81+
case .raw:
82+
// We need at least 11 bytes of random padding in order to safely encrypt messages
83+
guard blockSize >= bytes.count + 11 else { throw RSA.Error.invalidMessageLengthForEncryption }
84+
return Array(repeating: 0x00, count: blockSize - bytes.count) + bytes
85+
case .pksc1v15:
86+
guard !bytes.isEmpty else { throw RSA.Error.invalidMessageLengthForEncryption }
87+
// We need at least 11 bytes of random padding in order to safely encrypt messages
88+
guard blockSize >= bytes.count + 11 else { throw RSA.Error.invalidMessageLengthForEncryption }
89+
return Padding.eme_pkcs1v15.add(to: bytes, blockSize: blockSize)
9090
}
9191
}
92-
92+
9393
@inlinable
94-
internal func formatEncryptedBytes(_ bytes:Array<UInt8>, blockSize: Int) -> Array<UInt8> {
94+
internal func formatEncryptedBytes(_ bytes: Array<UInt8>, blockSize: Int) -> Array<UInt8> {
9595
switch self {
96-
case .unsafe:
97-
return bytes
98-
case .raw, .pksc1v15:
99-
// Format the encrypted bytes before returning
100-
var bytes = bytes
101-
if bytes.isEmpty {
102-
// Instead of returning an empty byte array, we return an array of zero's of length keySize bytes
103-
// This functionality matches that of Apple's `Security` framework
104-
return Array<UInt8>(repeating: 0, count: blockSize)
105-
} else {
106-
while bytes.count % 4 != 0 { bytes.insert(0x00, at: 0) }
96+
case .unsafe:
10797
return bytes
108-
}
98+
case .raw, .pksc1v15:
99+
// Format the encrypted bytes before returning
100+
var bytes = bytes
101+
if bytes.isEmpty {
102+
// Instead of returning an empty byte array, we return an array of zero's of length keySize bytes
103+
// This functionality matches that of Apple's `Security` framework
104+
return Array<UInt8>(repeating: 0, count: blockSize)
105+
} else {
106+
while bytes.count % 4 != 0 { bytes.insert(0x00, at: 0) }
107+
return bytes
108+
}
109109
}
110110
}
111111

112112
@inlinable
113113
internal func removePadding(_ bytes: Array<UInt8>, blockSize: Int) -> Array<UInt8> {
114114
switch self {
115-
case .unsafe:
116-
return bytes
117-
case .raw:
118-
return bytes
119-
case .pksc1v15:
120-
// Convert the Octet String into an Integer Primitive using the BigInteger `serialize` method
121-
// (this effectively just prefixes the data with a 0x00 byte indicating that its a positive integer)
122-
return Padding.eme_pkcs1v15.remove(from: [0x00] + bytes, blockSize: blockSize)
115+
case .unsafe:
116+
return bytes
117+
case .raw:
118+
return bytes
119+
case .pksc1v15:
120+
// Convert the Octet String into an Integer Primitive using the BigInteger `serialize` method
121+
// (this effectively just prefixes the data with a 0x00 byte indicating that its a positive integer)
122+
return Padding.eme_pkcs1v15.remove(from: [0x00] + bytes, blockSize: blockSize)
123123
}
124124
}
125125
}

Sources/CryptoSwift/RSA/RSA+Signature.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extension RSA: Signature {
1313
public func sign(_ bytes: ArraySlice<UInt8>) throws -> Array<UInt8> {
1414
try self.sign(Array(bytes), variant: .message_pkcs1v15_SHA512_256)
1515
}
16-
16+
1717
public func sign(_ bytes: Array<UInt8>, variant: SignatureVariant) throws -> Array<UInt8> {
1818
// Check for Private Exponent presence
1919
guard let d = d else {
@@ -32,7 +32,7 @@ extension RSA: Signature {
3232
public func verify(signature: ArraySlice<UInt8>, for expectedData: ArraySlice<UInt8>) throws -> Bool {
3333
try self.verify(signature: Array(signature), for: Array(expectedData), variant: .message_pkcs1v15_SHA512_256)
3434
}
35-
35+
3636
/// https://datatracker.ietf.org/doc/html/rfc8017#section-8.2.2
3737
public func verify(signature: Array<UInt8>, for bytes: Array<UInt8>, variant: SignatureVariant = .message_pkcs1v15_SHA256) throws -> Bool {
3838
/// Step 1: Ensure the signature is the same length as the key's modulus

0 commit comments

Comments
 (0)