Skip to content

Commit

Permalink
Add description for S3329 for Go
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-teuchert-sonarsource committed Feb 10, 2025
1 parent 174a4cc commit 26eaf53
Showing 1 changed file with 49 additions and 18 deletions.
67 changes: 49 additions & 18 deletions rules/S3329/go/rule.adoc
Original file line number Diff line number Diff line change
@@ -1,44 +1,75 @@
FIXME: add a description

// If you want to factorize the description uncomment the following line and create the file.
//include::../description.adoc[]
include::../summary.adoc[]

== Why is this an issue?

FIXME: remove the unused optional headers (that are commented out)
include::../rationale.adoc[]

//=== What is the potential impact?
include::../impact.adoc[]

== How to fix it
//== How to fix it in FRAMEWORK NAME

=== Code examples

==== Noncompliant code example

[source,go,diff-id=1,diff-type=noncompliant]
----
FIXME
import (
"crypto/cipher"
)
func encrypt(block cipher.Block, plaintext []byte) {
iv := []byte("fixed IVfixed IV")
encrypter := cipher.NewCBCEncrypter(block, iv)
encrypter.CryptBlocks(plaintext, plaintext)
}
----

==== Compliant solution

include::../common/fix/explicit-fix.adoc[]

[source,go,diff-id=1,diff-type=compliant]
----
FIXME
import (
"crypto/cipher"
"crypto/rand"
)
func encrypt(block cipher.Block, plaintext []byte) {
iv := make([]byte, block.BlockSize())
rand.Read(iv)
encrypter := cipher.NewCBCEncrypter(block, iv)
encrypter.CryptBlocks(plaintext, plaintext)
}
----

//=== How does this work?
=== How does this work?

include::../common/fix/fix.adoc[]



== Resources

include::../common/resources/docs.adoc[]

include::../common/resources/articles.adoc[]

include::../common/resources/presentations.adoc[]

include::../common/resources/standards.adoc[]

ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

//=== Pitfalls
include::../message.adoc[]

//=== Going the extra mile
'''

endif::env-github,rspecator-view[]

//== Resources
//=== Documentation
//=== Articles & blog posts
//=== Conference presentations
//=== Standards
//=== External coding guidelines
//=== Benchmarks

0 comments on commit 26eaf53

Please sign in to comment.