mirror of
https://github.com/absmach/supermq.git
synced 2026-06-23 06:50:18 +00:00
ef5c253c51
Continuous Delivery / lint-and-build (push) Has been cancelled
Continuous Delivery / Build and Push Docker Images (push) Has been cancelled
Deploy GitHub Pages / swagger-ui (push) Has been cancelled
CI Pipeline / Lint Proto (push) Has been cancelled
CI Pipeline / lint-and-build (push) Has been cancelled
CI Pipeline / Detect Changes (push) Has been cancelled
CI Pipeline / Test ${{ matrix.module }} (push) Has been cancelled
CI Pipeline / Upload Coverage (push) Has been cancelled
Property Based Tests / api-test (push) Has been cancelled
Signed-off-by: nyagamunene <stevenyaga2014@gmail.com> Signed-off-by: dusan <borovcanindusan1@gmail.com> Co-authored-by: Steve Munene <stevenyaga2014@gmail.com>
33 lines
757 B
Go
33 lines
757 B
Go
// Copyright (c) Abstract Machines
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package api
|
|
|
|
import "strings"
|
|
|
|
var serialReplacer = strings.NewReplacer(":", "", " ", "")
|
|
|
|
// 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
|
|
}
|
|
|
|
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])
|
|
}
|
|
|
|
return result.String()
|
|
}
|