Marco Borgeaud 8209548e54
Diff blocks: fix incorrect use for python (#2795)
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.
2023-08-21 15:22:49 +02:00

51 lines
1.0 KiB
Plaintext

== How to fix it in PyCrypto
=== Code examples
==== Noncompliant code example
include::../../common/fix/aes-noncompliant-example.adoc[]
[source,python,diff-id=11,diff-type=noncompliant]
----
from Crypto.Cipher import AES
AES.new(key, AES.MODE_ECB) # Noncompliant
----
include::../../common/fix/rsa-noncompliant-example.adoc[]
[source,python,diff-id=12,diff-type=noncompliant]
----
from Crypto.Cipher import PKCS1_v1_5
PKCS1_v1_5.new(key) # Noncompliant
----
==== Compliant solution
Since PyCrypto is not supported anymore, another library should be used.
In the current context, Cryptodome uses a similar API.
include::../../common/fix/aes-compliant-example.adoc[]
[source,python,diff-id=11,diff-type=compliant]
----
from Crypto.Cipher import AES
AES.new(key, AES.MODE_GCM)
----
include::../../common/fix/rsa-compliant-example.adoc[]
[source,python,diff-id=12,diff-type=compliant]
----
from Crypto.Cipher import PKCS1_OAEP
PKCS1_OAEP.new(key)
----
=== How does this work?
include::../../common/fix/fix.adoc[]