Skip to content
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
dborovcanin merged 11 commits into
absmach:mainfrom
nyagamunene:update-get-entity-id
Sep 30, 2025
Merged

NOISSUE - Normalize serial number for getEntityId method#169
dborovcanin merged 11 commits into
absmach:mainfrom
nyagamunene:update-get-entity-id

Conversation

@nyagamunene

Copy link
Copy Markdown
Contributor

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

Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>
Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>
@nyagamunene nyagamunene marked this pull request as ready for review September 22, 2025 15:00
WashingtonKK
WashingtonKK previously approved these changes Sep 22, 2025
Comment thread certs.go Outdated
Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>
Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>
WashingtonKK
WashingtonKK previously approved these changes Sep 23, 2025
Comment thread api/http/requests.go Outdated
Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>
SammyOina
SammyOina previously approved these changes Sep 23, 2025
@arvindh123 arvindh123 moved this to 🚀 Ready for merge in Magistrala Sep 25, 2025

@dborovcanin dborovcanin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this normalization needed?

Comment thread api/utils.go Outdated
Comment thread api/utils.go
cleaned = "0" + cleaned
}

var result strings.Builder

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grow immediately to avoid unnecessary allocations. Something like:

    n := len(cleaned) + (len(cleaned)/2 - 1)
	var b strings.Builder
	b.Grow(n)

@github-project-automation github-project-automation Bot moved this from 🚀 Ready for merge to 🚧 In Progress in Magistrala Sep 30, 2025
@nyagamunene

Copy link
Copy Markdown
Contributor Author

Why is this normalization needed?

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 dborovcanin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add tests for this. Also, make cases run in parallel to test the concurrent execution.

Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>
Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>
Comment thread api/utils.go Outdated
Comment on lines +22 to +27
var capacity int
if len(cleaned) >= 2 {
capacity = len(cleaned) + (len(cleaned)/2 - 1)
} else {
capacity = len(cleaned)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@github-project-automation github-project-automation Bot moved this from 🚧 In Progress to 🚀 Ready for merge in Magistrala Sep 30, 2025
@dborovcanin dborovcanin merged commit 982aba4 into absmach:main Sep 30, 2025
3 checks passed
@github-project-automation github-project-automation Bot moved this from 🚀 Ready for merge to ✅ Done in Magistrala Sep 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

5 participants