![github-actions[bot]](/assets/img/avatar_default.png)
* Add go to rule S5547 * Add description for S5547 for Go --------- Co-authored-by: daniel-teuchert-sonarsource <daniel-teuchert-sonarsource@users.noreply.github.com> Co-authored-by: Daniel Teuchert <daniel.teuchert@sonarsource.com>
75 lines
1.3 KiB
Plaintext
75 lines
1.3 KiB
Plaintext
include::../summary.adoc[]
|
|
|
|
== Why is this an issue?
|
|
|
|
include::../rationale.adoc[]
|
|
|
|
include::../impact.adoc[]
|
|
|
|
== How to fix it
|
|
|
|
=== Code examples
|
|
|
|
include::../common/fix/code-rationale.adoc[]
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,go,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
import (
|
|
"crypto/des"
|
|
"crypto/rand"
|
|
)
|
|
|
|
func encrypt(message []byte, key []byte) []byte {
|
|
blockCipher, _ := des.NewCipher(key) // Noncompliant
|
|
cipherText := make([]byte, blockCipher.BlockSize())
|
|
blockCipher.Encrypt(cipherText, message)
|
|
return cipherText
|
|
}
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,go,diff-id=1,diff-type=compliant]
|
|
----
|
|
import (
|
|
"crypto/aes"
|
|
"crypto/rand"
|
|
)
|
|
|
|
func encrypt(message []byte, key []byte) []byte {
|
|
blockCipher, _ := aes.NewCipher(key)
|
|
cipherText := make([]byte, blockCipher.BlockSize())
|
|
blockCipher.Encrypt(cipherText, message)
|
|
return cipherText
|
|
}
|
|
----
|
|
|
|
=== How does this work?
|
|
|
|
include::../common/fix/strong-cryptography.adoc[]
|
|
|
|
|
|
|
|
== Resources
|
|
|
|
include::../common/resources/standards.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[]
|
|
|