rspec/rules/S5547/swift/rule.adoc

88 lines
1.6 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
include::../description.adoc[]
=== Noncompliant code example
CommonCrypto library:
2022-02-04 17:28:24 +01:00
[source,swift]
----
import CommonCrypto
let algorithm = CCAlgorithm(kCCAlgorithmDES) // Noncompliant: 64 bits block size
----
https://github.com/iosdevzone/IDZSwiftCommonCrypto[IDZSwiftCommonCrypto] library:
2022-02-04 17:28:24 +01:00
[source,swift]
----
import IDZSwiftCommonCrypto
let algorithm = .des // Noncompliant: 64 bits block size
----
https://github.com/krzyzanowskim/CryptoSwift[CryptoSwift]
2022-02-04 17:28:24 +01:00
[source,swift]
----
import CryptoSwift
let blowfish = try Blowfish(key: key, blockMode: GCM(iv: iv, mode: .combined), padding: .pkcs7) // Noncompliant: 64 bits block size
----
=== Compliant solution
https://swift.org/blog/crypto/[Swift Crypto] library: prefer using this library which is native and officially supported by Apple
2022-02-04 17:28:24 +01:00
[source,swift]
----
import Crypto
let sealedBox = try AES.GCM.seal(input, using: key) // Compliant
----
CommonCrypto library:
2022-02-04 17:28:24 +01:00
[source,swift]
----
import CommonCrypto
let algorithm = CCAlgorithm(kCCAlgorithmAES) // Compliant
----
https://github.com/iosdevzone/IDZSwiftCommonCrypto[IDZSwiftCommonCrypto] library:
2022-02-04 17:28:24 +01:00
[source,swift]
----
import IDZSwiftCommonCrypto
let algorithm = .aes // Compliant
----
https://github.com/krzyzanowskim/CryptoSwift[CryptoSwift]
2022-02-04 17:28:24 +01:00
[source,swift]
----
import CryptoSwift
let aes = try AES(key: key, iv: iv) // Compliant
----
include::../see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]