
Improvement identified in #2790. Add a prefix to the diff-id when it is used multiple times in different "how to fix it in XYZ" sections to avoid ambiguity and pedantically follow the spec: > A single and unique diff-id should be used only once for each type of code example as shown in the description of a rule. Obvious typos around `diff-type` were fixed. An obvious extra use of diff blocks was removed.
33 lines
634 B
Plaintext
33 lines
634 B
Plaintext
== How to fix it in pyDes
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,python,diff-id=31,diff-type=noncompliant]
|
|
----
|
|
import pyDes
|
|
|
|
pyDes.des(key) # Noncompliant
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
Since pyDes only provides DES, it is recommended to use another library like pyca.
|
|
|
|
[source,python,diff-id=31,diff-type=compliant]
|
|
----
|
|
from cryptography.hazmat.primitives.ciphers import (
|
|
Cipher,
|
|
algorithms,
|
|
modes,
|
|
)
|
|
from cryptography.hazmat.backends import default_backend
|
|
|
|
Cipher(algorithms.AES(key), modes.GCM(iv), backend=default_backend())
|
|
----
|
|
|
|
=== How does this work?
|
|
|
|
include::../../common/fix/fix.adoc[]
|