Compare commits
4 Commits
3c779465e2
...
5a015d9609
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a015d9609 | ||
|
|
f929f33d1e | ||
|
|
6a1e9a387f | ||
|
|
75674b89d8 |
@ -93,11 +93,17 @@ type Builder struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetSeed derives a deterministic UUID from the given seed string.
|
// SetSeed derives a deterministic UUID from the given seed string.
|
||||||
// The seed is hashed once with SHA-256 and the first 16 bytes are used
|
// The seed is hashed once with SHA-256 and the first 16 bytes are
|
||||||
// as a fixed UUID for the manifest.
|
// used as a fixed UUID for the manifest.
|
||||||
func (b *Builder) SetSeed(seed string) {
|
func (b *Builder) SetSeed(seed string) {
|
||||||
|
b.fixedUUID = deriveSeedUUID(seed)
|
||||||
|
}
|
||||||
|
|
||||||
|
// deriveSeedUUID hashes the seed string with SHA-256
|
||||||
|
// and returns the first 16 bytes as a UUID.
|
||||||
|
func deriveSeedUUID(seed string) []byte {
|
||||||
hash := sha256.Sum256([]byte(seed))
|
hash := sha256.Sum256([]byte(seed))
|
||||||
b.fixedUUID = hash[:16]
|
return hash[:16]
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBuilder creates a new Builder.
|
// NewBuilder creates a new Builder.
|
||||||
|
|||||||
@ -150,17 +150,15 @@ func TestBuilderDeterministicOutput(t *testing.T) {
|
|||||||
assert.Equal(t, out1, out2, "two builds with same input should produce byte-identical output")
|
assert.Equal(t, out1, out2, "two builds with same input should produce byte-identical output")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetSeedDeterministic(t *testing.T) {
|
func TestDeriveSeedUUID(t *testing.T) {
|
||||||
b1 := NewBuilder()
|
|
||||||
b1.SetSeed("test-seed-value")
|
|
||||||
b2 := NewBuilder()
|
|
||||||
b2.SetSeed("test-seed-value")
|
|
||||||
assert.Equal(t, b1.fixedUUID, b2.fixedUUID, "same seed should produce same UUID")
|
|
||||||
assert.Len(t, b1.fixedUUID, 16, "UUID should be 16 bytes")
|
|
||||||
|
|
||||||
b3 := NewBuilder()
|
uuid1 := deriveSeedUUID("test-seed-value")
|
||||||
b3.SetSeed("different-seed")
|
uuid2 := deriveSeedUUID("test-seed-value")
|
||||||
assert.NotEqual(t, b1.fixedUUID, b3.fixedUUID, "different seeds should produce different UUIDs")
|
assert.Equal(t, uuid1, uuid2, "same seed should produce same UUID")
|
||||||
|
assert.Len(t, uuid1, 16, "UUID should be 16 bytes")
|
||||||
|
|
||||||
|
uuid3 := deriveSeedUUID("different-seed")
|
||||||
|
assert.NotEqual(t, uuid1, uuid3, "different seeds should produce different UUIDs")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuilderBuildEmpty(t *testing.T) {
|
func TestBuilderBuildEmpty(t *testing.T) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user