rspec/rules/S4790/go/rule.adoc
github-actions[bot] 7fe7e1eda0
Create rule S4790: Using weak hashing algorithms is security-sensitive: add Go (#2753)
You can preview this rule
[here](https://sonarsource.github.io/rspec/#/rspec/S4790/go) (updated a
few minutes after each push).

## 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)
2023-08-03 16:06:34 +02:00

87 lines
1.4 KiB
Plaintext

include::../description.adoc[]
include::../ask-yourself.adoc[]
include::../recommended.adoc[]
== Sensitive Code Example
[source,go,diff-id=1,diff-type=noncompliant]
----
import (
"crypto"
"fmt"
)
func calculateHash(data []byte) string {
hashInstance := crypto.Hash.New(crypto.MD5) // Sensitive
hashInstance.Write(data)
hash := hashInstance.Sum(nil)
return fmt.Sprintf("%x", hash)
}
----
[source,go,diff-id=2,diff-type=noncompliant]
----
import (
"crypto/sha1"
"fmt"
)
func calculateHash(data []byte) string {
hash := sha1.Sum(data) // Sensitive
return fmt.Sprintf("%x", hash)
}
----
== Compliant Solution
[source,go,diff-id=1,diff-type=compliant]
----
import (
"crypto"
"fmt"
)
func calculateHash(data []byte) string {
hashInstance := crypto.Hash.New(crypto.SHA256) // Compliant
hashInstance.Write(data)
hash := hashInstance.Sum(nil)
return fmt.Sprintf("%x", hash)
}
----
[source,go,diff-id=2,diff-type=compliant]
----
import (
"crypto/sha512"
"fmt"
)
func calculateHash(data []byte) string {
hash := sha512.Sum512(data) // Compliant
return fmt.Sprintf("%x", hash)
}
----
include::../see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
include::../highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]