Skip to content

Commit 7351b5c

Browse files
committed
README: fix Swift snippets; correct AEAD decrypt tag param; clarify key/iv sizes
- Use inline comments for ellipses in array literals. - Specify 32-byte AES key and 16-byte CBC IV in examples. - Initialize iv and RSA n/e/d with [] placeholders and comments. - Fix AEADChaCha20Poly1305.decrypt example to use authenticationTag: tag.
1 parent 5823b6b commit 7351b5c

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

‎README.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ data.crc32()
306306

307307
```swift
308308
// Calculate Message Authentication Code (MAC) for message
309-
let key: Array<UInt8> = [1,2,3,4,5,6,7,8,9,10,...]
309+
let key: Array<UInt8> = [1,2,3,4,5,6,7,8,9,10 /* ... */]
310310

311311
try Poly1305(key: key).authenticate(bytes)
312312
try HMAC(key: key, variant: .sha256).authenticate(bytes)
@@ -382,7 +382,7 @@ Variant of AES encryption (AES-128, AES-192, AES-256) depends on given key lengt
382382
AES-256 example
383383

384384
```swift
385-
let encryptedBytes = try AES(key: [1,2,3,...,32], blockMode: CBC(iv: [1,2,3,...,16]), padding: .pkcs7)
385+
let encryptedBytes = try AES(key: [1,2,3 /* ... 32 bytes total */], blockMode: CBC(iv: [1,2,3 /* ... 16 bytes total */]), padding: .pkcs7)
386386
```
387387

388388
Full example:
@@ -451,7 +451,7 @@ do {
451451
let input: Array<UInt8> = [0,1,2,3,4,5,6,7,8,9]
452452

453453
let key: Array<UInt8> = [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
454-
let iv: Array<UInt8> = // Random bytes of `AES.blockSize` length
454+
let iv: Array<UInt8> = [] // Random bytes of `AES.blockSize` length
455455

456456
do {
457457
let encrypted = try AES(key: key, blockMode: CBC(iv: iv), padding: .pkcs7).encrypt(input)
@@ -531,7 +531,7 @@ Check documentation or CCM specification for valid parameters for CCM.
531531

532532
```swift
533533
let encrypt = try AEADChaCha20Poly1305.encrypt(plaintext, key: key, iv: nonce, authenticationHeader: header)
534-
let decrypt = try AEADChaCha20Poly1305.decrypt(ciphertext, key: key, iv: nonce, authenticationHeader: header, authenticationTag: tagArr: tag)
534+
let decrypt = try AEADChaCha20Poly1305.decrypt(ciphertext, key: key, iv: nonce, authenticationHeader: header, authenticationTag: tag)
535535
```
536536

537537
##### RSA
@@ -541,9 +541,9 @@ RSA initialization from parameters
541541
```swift
542542
let input: Array<UInt8> = [0,1,2,3,4,5,6,7,8,9]
543543

544-
let n: Array<UInt8> = // RSA modulus
545-
let e: Array<UInt8> = // RSA public exponent
546-
let d: Array<UInt8> = // RSA private exponent
544+
let n: Array<UInt8> = [] // RSA modulus
545+
let e: Array<UInt8> = [] // RSA public exponent
546+
let d: Array<UInt8> = [] // RSA private exponent
547547

548548
let rsa = RSA(n: n, e: e, d: d)
549549

0 commit comments

Comments
 (0)