v0.0.296 add csid.generateIDFromSeed
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m4s
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m4s
This commit is contained in:
parent
2fbd5cf965
commit
f8c0c0afa0
@ -65,6 +65,27 @@ func generateID(prefix string) string {
|
||||
return prefix + k + checkstr
|
||||
}
|
||||
|
||||
func generateIDFromSeed(prefix string, seed string) string {
|
||||
h := sha256.New()
|
||||
|
||||
iddata := ""
|
||||
for len(iddata) < idlen-len(prefix)-checklen {
|
||||
h.Write([]byte(seed))
|
||||
bs := h.Sum(nil)
|
||||
iddata += langext.NewAnyBaseConverter(idCharset).Encode(bs)
|
||||
}
|
||||
|
||||
checksum := 0
|
||||
for i := 0; i < idlen-len(prefix)-checklen; i++ {
|
||||
ichr := int(iddata[i])
|
||||
checksum = (checksum + charSetReverseMap[ichr]) % (idCharsetLen)
|
||||
}
|
||||
|
||||
checkstr := string(idCharset[checksum%idCharsetLen])
|
||||
|
||||
return prefix + iddata[:(idlen-len(prefix)-checklen)] + checkstr
|
||||
}
|
||||
|
||||
func validateID(prefix string, value string) error {
|
||||
if len(value) != idlen {
|
||||
return exerr.New(exerr.TypeInvalidCSID, "id has the wrong length").Str("value", value).Build()
|
||||
|
@ -1,5 +1,5 @@
|
||||
package goext
|
||||
|
||||
const GoextVersion = "0.0.295"
|
||||
const GoextVersion = "0.0.296"
|
||||
|
||||
const GoextVersionTimestamp = "2023-11-01T00:23:17+0100"
|
||||
const GoextVersionTimestamp = "2023-11-01T00:29:58+0100"
|
||||
|
Loading…
Reference in New Issue
Block a user