Loris S 981e54d330
Modify S3329: Learn-As-You-Code migration (#2293)
## Review

A dedicated reviewer checked the rule description successfully for:

- [x] logical errors and incorrect information
- [x] information gaps and missing content
- [x] text style and tone
- [x] PR summary and labels follow [the
guidelines](https://github.com/SonarSource/rspec/#to-modify-an-existing-rule)

---------

Co-authored-by: hendrik-buchwald-sonarsource <64110887+hendrik-buchwald-sonarsource@users.noreply.github.com>
2023-06-28 17:25:56 +02:00

47 lines
787 B
Plaintext

== How to fix it in pyca
=== Code examples
==== Noncompliant code example
[source,python,diff-id=1,diff-type=noncompliant]
----
from cryptography.hazmat.primitives.ciphers import (
Cipher,
algorithms,
modes,
)
iv = "doNotTryThis@Home2023"
cipher = Cipher(algorithms.AES(key), modes.CBC(iv))
cipher.encryptor() # Noncompliant
----
==== Compliant solution
:explicit_strong: os.urandom
include::../../common/fix/explicit-fix.adoc[]
[source,python,diff-id=1,diff-type=compliant]
----
from os import urandom
from cryptography.hazmat.primitives.ciphers import (
Cipher,
algorithms,
modes,
)
iv = urandom(16)
cipher = Cipher(algorithms.AES(key), modes.CBC(iv))
cipher.encryptor()
----
=== How does this work?
include::../../common/fix/fix.adoc[]