Skip to content

Commit 3fc9ca8

Browse files
committed
change UpdableCryptor to accept any SequenceType instead of Array
1 parent b4f932c commit 3fc9ca8

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

Sources/CryptoSwift/AES.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ extension AES {
403403
self.paddingRequired = aes.blockMode.options.contains(.PaddingRequired)
404404
}
405405

406-
mutating public func update(withBytes bytes:Array<UInt8>, isLast: Bool = false) throws -> Array<UInt8> {
406+
mutating public func update<T: SequenceType where T.Generator.Element == UInt8>(withBytes bytes:T, isLast: Bool = false) throws -> Array<UInt8> {
407407
self.accumulated += bytes
408408

409409
if isLast {
@@ -445,7 +445,7 @@ extension AES {
445445
self.paddingRequired = aes.blockMode.options.contains(.PaddingRequired);
446446
}
447447

448-
mutating public func update(withBytes bytes:Array<UInt8>, isLast: Bool = false) throws -> Array<UInt8> {
448+
mutating public func update<T: SequenceType where T.Generator.Element == UInt8>(withBytes bytes:T, isLast: Bool = false) throws -> Array<UInt8> {
449449
self.accumulated += bytes
450450

451451
var plaintext = Array<UInt8>()

Sources/CryptoSwift/UpdatableCryptor.swift

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,52 @@ public protocol UpdatableCryptor {
1212
/// - parameter bytes: Bytes to process
1313
/// - parameter isLast: (Optional) Given chunk is the last one. No more updates after this call.
1414
/// - returns: Processed data or empty array.
15-
mutating func update(withBytes bytes:Array<UInt8>, isLast: Bool) throws -> Array<UInt8>
15+
mutating func update<T: SequenceType where T.Generator.Element == UInt8>(withBytes bytes:T, isLast: Bool) throws -> Array<UInt8>
1616

1717
/// Encrypt/Decrypt given bytes in chunks.
1818
///
1919
/// - parameter bytes: Bytes to process
2020
/// - parameter isLast: (Optional) Given chunk is the last one. No more updates after this call.
2121
/// - parameter output: Resulting data
2222
/// - returns: Processed data or empty array.
23-
mutating func update(withBytes bytes:Array<UInt8>, isLast: Bool, output: (Array<UInt8>) -> Void) throws
23+
mutating func update<T: SequenceType where T.Generator.Element == UInt8>(withBytes bytes:T, isLast: Bool, output: (Array<UInt8>) -> Void) throws
2424

2525
/// Finish encryption/decryption. This may apply padding.
2626
/// - parameter bytes: Bytes to process
2727
/// - returns: Processed data.
28-
mutating func finish(withBytes bytes:Array<UInt8>) throws -> Array<UInt8>
28+
mutating func finish<T: SequenceType where T.Generator.Element == UInt8>(withBytes bytes:T) throws -> Array<UInt8>
2929

3030
/// Finish encryption/decryption. This may apply padding.
3131
/// - parameter bytes: Bytes to process
3232
/// - parameter output: Resulting data
3333
/// - returns: Processed data.
34-
mutating func finish(withBytes bytes:Array<UInt8>, output: (Array<UInt8>) -> Void) throws
34+
mutating func finish<T: SequenceType where T.Generator.Element == UInt8>(withBytes bytes:T, output: (Array<UInt8>) -> Void) throws
3535
}
3636

3737
extension UpdatableCryptor {
38-
mutating public func update(withBytes bytes:Array<UInt8>, isLast: Bool = false, output: (Array<UInt8>) -> Void) throws {
38+
mutating public func update<T: SequenceType where T.Generator.Element == UInt8>(withBytes bytes:T, isLast: Bool = false, output: (Array<UInt8>) -> Void) throws {
3939
let processed = try self.update(withBytes: bytes, isLast: isLast)
4040
if (!processed.isEmpty) {
4141
output(processed)
4242
}
4343
}
4444

45-
mutating public func finish(withBytes bytes:Array<UInt8> = []) throws -> Array<UInt8> {
45+
mutating public func finish<T: SequenceType where T.Generator.Element == UInt8>(withBytes bytes:T) throws -> Array<UInt8> {
4646
return try self.update(withBytes: bytes, isLast: true)
4747
}
48+
49+
mutating public func finish() throws -> Array<UInt8> {
50+
return try self.update(withBytes: [], isLast: true)
51+
}
4852

49-
mutating public func finish(withBytes bytes:Array<UInt8> = [], output: (Array<UInt8>) -> Void) throws {
53+
mutating public func finish<T: SequenceType where T.Generator.Element == UInt8>(withBytes bytes:T, output: (Array<UInt8>) -> Void) throws {
5054
let processed = try self.update(withBytes: bytes, isLast: true)
5155
if (!processed.isEmpty) {
5256
output(processed)
5357
}
5458
}
59+
60+
mutating public func finish(output: (Array<UInt8>) -> Void) throws {
61+
try self.finish(withBytes: [], output: output)
62+
}
5563
}

0 commit comments

Comments
 (0)