Skip to content

Commit 2c06f88

Browse files
authored
Merge pull request #1076 from mluisbrown/michael/rename-data-bytes-to-bytearray
2 parents b7a06ec + bdebd4b commit 2c06f88

File tree

13 files changed

+71
-71
lines changed

13 files changed

+71
-71
lines changed

Sources/CryptoSwift/ASN1/ASN1Encoder.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ extension ASN1 {
2828
public static func encode(_ node: ASN1.Node) -> [UInt8] {
2929
switch node {
3030
case .integer(let integer):
31-
return IDENTIFIERS.INTERGER.bytes + self.asn1LengthPrefixed(integer.bytes)
31+
return IDENTIFIERS.INTERGER.bytes + self.asn1LengthPrefixed(integer.byteArray)
3232
case .bitString(let bits):
33-
return IDENTIFIERS.BITSTRING.bytes + self.asn1LengthPrefixed([0x00] + bits.bytes)
33+
return IDENTIFIERS.BITSTRING.bytes + self.asn1LengthPrefixed([0x00] + bits.byteArray)
3434
case .octetString(let octet):
35-
return IDENTIFIERS.OCTETSTRING.bytes + self.asn1LengthPrefixed(octet.bytes)
35+
return IDENTIFIERS.OCTETSTRING.bytes + self.asn1LengthPrefixed(octet.byteArray)
3636
case .null:
3737
return IDENTIFIERS.NULL.bytes
3838
case .objectIdentifier(let oid):
39-
return IDENTIFIERS.OBJECTID.bytes + self.asn1LengthPrefixed(oid.bytes)
39+
return IDENTIFIERS.OBJECTID.bytes + self.asn1LengthPrefixed(oid.byteArray)
4040
case .sequence(let nodes):
4141
return IDENTIFIERS.SEQUENCE.bytes + self.asn1LengthPrefixed( nodes.reduce(into: Array<UInt8>(), { partialResult, node in
4242
partialResult += encode(node)

Sources/CryptoSwift/Foundation/Array+Foundation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ public extension Array where Element == UInt8 {
2727
return
2828
}
2929

30-
append(contentsOf: decodedData.bytes)
30+
append(contentsOf: decodedData.byteArray)
3131
}
3232
}

Sources/CryptoSwift/Foundation/Data+Extension.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,55 +25,55 @@ extension Data {
2525
}
2626

2727
public func md5() -> Data {
28-
Data( Digest.md5(bytes))
28+
Data( Digest.md5(byteArray))
2929
}
3030

3131
public func sha1() -> Data {
32-
Data( Digest.sha1(bytes))
32+
Data( Digest.sha1(byteArray))
3333
}
3434

3535
public func sha224() -> Data {
36-
Data( Digest.sha224(bytes))
36+
Data( Digest.sha224(byteArray))
3737
}
3838

3939
public func sha256() -> Data {
40-
Data( Digest.sha256(bytes))
40+
Data( Digest.sha256(byteArray))
4141
}
4242

4343
public func sha384() -> Data {
44-
Data( Digest.sha384(bytes))
44+
Data( Digest.sha384(byteArray))
4545
}
4646

4747
public func sha512() -> Data {
48-
Data( Digest.sha512(bytes))
48+
Data( Digest.sha512(byteArray))
4949
}
5050

5151
public func sha3(_ variant: SHA3.Variant) -> Data {
52-
Data( Digest.sha3(bytes, variant: variant))
52+
Data( Digest.sha3(byteArray, variant: variant))
5353
}
5454

5555
public func crc32(seed: UInt32? = nil, reflect: Bool = true) -> Data {
56-
Data( Checksum.crc32(bytes, seed: seed, reflect: reflect).bytes())
56+
Data( Checksum.crc32(byteArray, seed: seed, reflect: reflect).bytes())
5757
}
5858

5959
public func crc32c(seed: UInt32? = nil, reflect: Bool = true) -> Data {
60-
Data( Checksum.crc32c(bytes, seed: seed, reflect: reflect).bytes())
60+
Data( Checksum.crc32c(byteArray, seed: seed, reflect: reflect).bytes())
6161
}
6262

6363
public func crc16(seed: UInt16? = nil) -> Data {
64-
Data( Checksum.crc16(bytes, seed: seed).bytes())
64+
Data( Checksum.crc16(byteArray, seed: seed).bytes())
6565
}
6666

6767
public func encrypt(cipher: Cipher) throws -> Data {
68-
Data( try cipher.encrypt(bytes.slice))
68+
Data( try cipher.encrypt(byteArray.slice))
6969
}
7070

7171
public func decrypt(cipher: Cipher) throws -> Data {
72-
Data( try cipher.decrypt(bytes.slice))
72+
Data( try cipher.decrypt(byteArray.slice))
7373
}
7474

7575
public func authenticate(with authenticator: Authenticator) throws -> Data {
76-
Data( try authenticator.authenticate(bytes))
76+
Data( try authenticator.authenticate(byteArray))
7777
}
7878
}
7979

@@ -82,11 +82,11 @@ extension Data {
8282
self.init(Array<UInt8>(hex: hex))
8383
}
8484

85-
public var bytes: Array<UInt8> {
85+
public var byteArray: Array<UInt8> {
8686
Array(self)
8787
}
8888

8989
public func toHexString() -> String {
90-
self.bytes.toHexString()
90+
self.byteArray.toHexString()
9191
}
9292
}

Sources/CryptoSwift/Foundation/String+FoundationExtension.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ extension String {
3636
throw CipherError.decrypt
3737
}
3838

39-
return try decodedData.decrypt(cipher: cipher).bytes
39+
return try decodedData.decrypt(cipher: cipher).byteArray
4040
}
4141
}

Sources/CryptoSwift/RSA/RSA+Cipher.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ extension RSA: Cipher {
3636
@inlinable
3737
internal func encryptPreparedBytes(_ bytes: Array<UInt8>) throws -> Array<UInt8> {
3838
// Calculate encrypted data
39-
return BigUInteger(Data(bytes)).power(self.e, modulus: self.n).serialize().bytes
39+
return BigUInteger(Data(bytes)).power(self.e, modulus: self.n).serialize().byteArray
4040
}
4141

4242
@inlinable
@@ -59,7 +59,7 @@ extension RSA: Cipher {
5959
guard let d = d else { throw RSA.Error.noPrivateKey }
6060

6161
// Calculate decrypted data
62-
return BigUInteger(Data(bytes)).power(d, modulus: self.n).serialize().bytes
62+
return BigUInteger(Data(bytes)).power(d, modulus: self.n).serialize().byteArray
6363
}
6464
}
6565

Sources/CryptoSwift/RSA/RSA+Signature.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extension RSA: Signature {
3535
let hashedAndEncoded = try RSA.hashedAndEncoded(bytes, variant: variant, keySizeInBytes: self.keySizeBytes)
3636

3737
/// Calculate the Signature
38-
let signedData = BigUInteger(Data(hashedAndEncoded)).power(d, modulus: self.n).serialize().bytes
38+
let signedData = BigUInteger(Data(hashedAndEncoded)).power(d, modulus: self.n).serialize().byteArray
3939

4040
return variant.formatSignedBytes(signedData, blockSize: self.keySizeBytes)
4141
}
@@ -61,7 +61,7 @@ extension RSA: Signature {
6161
if expectedData.count == self.keySizeBytes && expectedData.prefix(1) == [0x00] { expectedData = Array(expectedData.dropFirst()) }
6262

6363
/// Step 2: 'Decrypt' the signature
64-
let signatureResult = BigUInteger(Data(signature)).power(self.e, modulus: self.n).serialize().bytes
64+
let signatureResult = BigUInteger(Data(signature)).power(self.e, modulus: self.n).serialize().byteArray
6565

6666
/// Step 3: Compare the 'decrypted' signature with the prepared / encoded expected message....
6767
guard signatureResult == expectedData else { return false }

Sources/CryptoSwift/RSA/RSA.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ extension RSA {
259259
/// // rsaKey.verify(...)
260260
/// ```
261261
public convenience init(rawRepresentation raw: Data) throws {
262-
do { try self.init(privateDER: raw.bytes) } catch {
263-
try self.init(publicDER: raw.bytes)
262+
do { try self.init(privateDER: raw.byteArray) } catch {
263+
try self.init(publicDER: raw.byteArray)
264264
}
265265
}
266266
}
@@ -286,8 +286,8 @@ extension RSA {
286286
let exp = self.e.serialize()
287287
let pubKeyAsnNode: ASN1.Node =
288288
.sequence(nodes: [
289-
.integer(data: DER.i2ospData(x: mod.bytes, size: self.keySizeBytes)),
290-
.integer(data: DER.i2ospData(x: exp.bytes, size: exp.bytes.count))
289+
.integer(data: DER.i2ospData(x: mod.byteArray, size: self.keySizeBytes)),
290+
.integer(data: DER.i2ospData(x: exp.byteArray, size: exp.byteArray.count))
291291
])
292292
return ASN1.Encoder.encode(pubKeyAsnNode)
293293
}
@@ -326,14 +326,14 @@ extension RSA {
326326
let privateKeyAsnNode: ASN1.Node =
327327
.sequence(nodes: [
328328
.integer(data: Data(hex: "0x00")),
329-
.integer(data: DER.i2ospData(x: mod.bytes, size: self.keySizeBytes)),
330-
.integer(data: DER.i2ospData(x: self.e.serialize().bytes, size: 3)),
331-
.integer(data: DER.i2ospData(x: d.serialize().bytes, size: self.keySizeBytes)),
332-
.integer(data: DER.i2ospData(x: primes.p.serialize().bytes, size: paramWidth)),
333-
.integer(data: DER.i2ospData(x: primes.q.serialize().bytes, size: paramWidth)),
334-
.integer(data: DER.i2ospData(x: (d % (primes.p - 1)).serialize().bytes, size: paramWidth)),
335-
.integer(data: DER.i2ospData(x: (d % (primes.q - 1)).serialize().bytes, size: paramWidth)),
336-
.integer(data: DER.i2ospData(x: coefficient.serialize().bytes, size: paramWidth))
329+
.integer(data: DER.i2ospData(x: mod.byteArray, size: self.keySizeBytes)),
330+
.integer(data: DER.i2ospData(x: self.e.serialize().byteArray, size: 3)),
331+
.integer(data: DER.i2ospData(x: d.serialize().byteArray, size: self.keySizeBytes)),
332+
.integer(data: DER.i2ospData(x: primes.p.serialize().byteArray, size: paramWidth)),
333+
.integer(data: DER.i2ospData(x: primes.q.serialize().byteArray, size: paramWidth)),
334+
.integer(data: DER.i2ospData(x: (d % (primes.p - 1)).serialize().byteArray, size: paramWidth)),
335+
.integer(data: DER.i2ospData(x: (d % (primes.q - 1)).serialize().byteArray, size: paramWidth)),
336+
.integer(data: DER.i2ospData(x: coefficient.serialize().byteArray, size: paramWidth))
337337
])
338338

339339
// Encode and return the data

Sources/CryptoSwift/String+Extension.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extension String {
2020

2121
@inlinable
2222
public var bytes: Array<UInt8> {
23-
data(using: String.Encoding.utf8, allowLossyConversion: true)?.bytes ?? Array(utf8)
23+
data(using: String.Encoding.utf8, allowLossyConversion: true)?.byteArray ?? Array(utf8)
2424
}
2525

2626
@inlinable

Sources/CryptoSwift/UInt128.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct UInt128: Equatable, ExpressibleByIntegerLiteral {
5858
var result = Data()
5959
result.append(ar)
6060
result.append(br)
61-
return result.bytes
61+
return result.byteArray
6262
}
6363

6464
static func ^ (n1: UInt128, n2: UInt128) -> UInt128 {

Tests/CryptoSwiftTests/Access.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class Access: XCTestCase {
142142
_ = data.crc32()
143143
_ = data.crc32c()
144144

145-
_ = data.bytes
145+
_ = data.byteArray
146146
_ = data.toHexString()
147147

148148
do {

0 commit comments

Comments
 (0)