@@ -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 }
0 commit comments