Эх сурвалжийг харах

Minor comments update to playground examples

Marcin Krzyżanowski 9 жил өмнө
parent
commit
03e2804cae

+ 16 - 6
CryptoSwift.playground/Contents.swift

@@ -7,8 +7,11 @@ import CryptoSwift
 import Foundation
 import Foundation
 import XCPlayground
 import XCPlayground
 
 
-//: # AES
-//: One-time shot
+/*: 
+ # AES
+ ### One-time shot.
+ Encrypt all data at once.
+ */
 do {
 do {
     let aes = try AES(key: "passwordpassword", iv: "drowssapdrowssap")
     let aes = try AES(key: "passwordpassword", iv: "drowssapdrowssap")
     let ciphertext = try aes.encrypt("Nullam quis risus eget urna mollis ornare vel eu leo.".utf8.map({$0}))
     let ciphertext = try aes.encrypt("Nullam quis risus eget urna mollis ornare vel eu leo.".utf8.map({$0}))
@@ -17,15 +20,20 @@ do {
     print(error)
     print(error)
 }
 }
 
 
-//: Incremental encryption
+/*:
+ ### Incremental encryption
+
+ Instantiate Encryptor for AES encryption (or decryptor for decryption) and process input data partially.
+ */
 do {
 do {
-    let aes = try AES(key: "passwordpassword", iv: "drowssapdrowssap")
-    var encryptor = aes.makeEncryptor()
+    var encryptor = try AES(key: "passwordpassword", iv: "drowssapdrowssap").makeEncryptor()
 
 
     var ciphertext = Array<UInt8>()
     var ciphertext = Array<UInt8>()
+    // aggregate partial results
     ciphertext += try encryptor.update(withBytes: "Nullam quis risus ".utf8.map({$0}))
     ciphertext += try encryptor.update(withBytes: "Nullam quis risus ".utf8.map({$0}))
     ciphertext += try encryptor.update(withBytes: "eget urna mollis ".utf8.map({$0}))
     ciphertext += try encryptor.update(withBytes: "eget urna mollis ".utf8.map({$0}))
     ciphertext += try encryptor.update(withBytes: "ornare vel eu leo.".utf8.map({$0}))
     ciphertext += try encryptor.update(withBytes: "ornare vel eu leo.".utf8.map({$0}))
+    // finish at the end
     ciphertext += try encryptor.finish()
     ciphertext += try encryptor.finish()
 
 
     print(ciphertext.toHexString())
     print(ciphertext.toHexString())
@@ -33,7 +41,9 @@ do {
     print(error)
     print(error)
 }
 }
 
 
-//: Encrypt stream incrementally
+/*:
+ ### Encrypt stream
+ */
 do {
 do {
     // write until all is written
     // write until all is written
     func writeToStream(stream: NSOutputStream, bytes: Array<UInt8>) {
     func writeToStream(stream: NSOutputStream, bytes: Array<UInt8>) {