This repository was archived by the owner on Apr 6, 2026. It is now read-only.
NOISSUE - Normalize serial number for getEntityId method#169
Merged
Conversation
Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>
Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>
WashingtonKK
previously approved these changes
Sep 22, 2025
SammyOina
suggested changes
Sep 22, 2025
Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>
Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>
WashingtonKK
previously approved these changes
Sep 23, 2025
SammyOina
suggested changes
Sep 23, 2025
Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>
SammyOina
previously approved these changes
Sep 23, 2025
dborovcanin
suggested changes
Sep 30, 2025
dborovcanin
left a comment
Contributor
There was a problem hiding this comment.
Why is this normalization needed?
| cleaned = "0" + cleaned | ||
| } | ||
|
|
||
| var result strings.Builder |
Contributor
There was a problem hiding this comment.
Grow immediately to avoid unnecessary allocations. Something like:
n := len(cleaned) + (len(cleaned)/2 - 1)
var b strings.Builder
b.Grow(n)
Contributor
Author
Openbao serial numbers have semicolons in them but when the certificate is generated the colons are omitted. |
Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>
dborovcanin
suggested changes
Sep 30, 2025
dborovcanin
left a comment
Contributor
There was a problem hiding this comment.
Add tests for this. Also, make cases run in parallel to test the concurrent execution.
Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>
dborovcanin
suggested changes
Sep 30, 2025
Comment on lines
+22
to
+27
| var capacity int | ||
| if len(cleaned) >= 2 { | ||
| capacity = len(cleaned) + (len(cleaned)/2 - 1) | ||
| } else { | ||
| capacity = len(cleaned) | ||
| } |
Contributor
There was a problem hiding this comment.
If len is less than 2 - it indicates an empty string or something worse. We can handle it at the very begging, something like:
// NormalizeSerialNumber normalizes a serial number to use colon-separated hex format.
func NormalizeSerialNumber(serial string) string {
if len(serial) < 2 {
return serialReplacer.Replace(serial)
}
cleaned := serialReplacer.Replace(serial)
cleaned = strings.ToLower(cleaned)
if len(cleaned)%2 != 0 {
cleaned = "0" + cleaned
}
// An empty line indicating cleanup is done, now we want to build normalized record.
capacity := len(cleaned) + (len(cleaned)/2 - 1)
var result strings.Builder
result.Grow(capacity)
for i := 0; i < len(cleaned); i += 2 {
if i > 0 {
result.WriteString(":")
}
result.WriteString(cleaned[i : i+2])
}
// An empty line is optional, we are not consistent within the codebase, unfortunately.
return result.String()
}Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>
Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>
Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>
dborovcanin
approved these changes
Sep 30, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
What does this do?
Which issue(s) does this PR fix/relate to?
Have you included tests for your changes?
Did you document any new/modified features?
Notes