2021-03-12 12:57:23 +00:00
|
|
|
package refstest
|
|
|
|
|
|
|
|
import (
|
2024-08-26 11:13:20 +00:00
|
|
|
crand "crypto/rand"
|
|
|
|
"crypto/sha256"
|
2022-02-22 11:25:43 +00:00
|
|
|
|
2023-03-07 10:38:56 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
|
2021-03-12 12:57:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func GenerateVersion(empty bool) *refs.Version {
|
|
|
|
m := new(refs.Version)
|
|
|
|
|
|
|
|
if !empty {
|
|
|
|
m.SetMajor(2)
|
|
|
|
m.SetMinor(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateOwnerID(empty bool) *refs.OwnerID {
|
|
|
|
m := new(refs.OwnerID)
|
|
|
|
|
|
|
|
if !empty {
|
2024-08-26 11:13:20 +00:00
|
|
|
id := make([]byte, 25)
|
|
|
|
_, _ = crand.Read(id)
|
|
|
|
|
|
|
|
m.SetValue(id)
|
2021-03-12 12:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateAddress(empty bool) *refs.Address {
|
|
|
|
m := new(refs.Address)
|
|
|
|
|
2021-06-11 12:41:36 +00:00
|
|
|
if !empty {
|
|
|
|
m.SetObjectID(GenerateObjectID(false))
|
|
|
|
m.SetContainerID(GenerateContainerID(false))
|
|
|
|
}
|
2021-03-12 12:57:23 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateObjectID(empty bool) *refs.ObjectID {
|
|
|
|
m := new(refs.ObjectID)
|
|
|
|
|
|
|
|
if !empty {
|
2024-08-26 11:13:20 +00:00
|
|
|
id := make([]byte, sha256.Size)
|
|
|
|
_, _ = crand.Read(id)
|
|
|
|
|
|
|
|
m.SetValue(id)
|
2021-03-12 12:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2022-03-01 12:50:09 +00:00
|
|
|
func GenerateObjectIDs(empty bool) []refs.ObjectID {
|
|
|
|
var ids []refs.ObjectID
|
2021-03-12 12:57:23 +00:00
|
|
|
|
|
|
|
if !empty {
|
|
|
|
ids = append(ids,
|
2022-03-01 12:50:09 +00:00
|
|
|
*GenerateObjectID(false),
|
|
|
|
*GenerateObjectID(false),
|
2021-03-12 12:57:23 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ids
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateContainerID(empty bool) *refs.ContainerID {
|
|
|
|
m := new(refs.ContainerID)
|
|
|
|
|
|
|
|
if !empty {
|
2024-08-26 11:13:20 +00:00
|
|
|
id := make([]byte, sha256.Size)
|
|
|
|
_, _ = crand.Read(id)
|
|
|
|
|
|
|
|
m.SetValue(id)
|
2021-03-12 12:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2022-03-02 08:18:59 +00:00
|
|
|
func GenerateContainerIDs(empty bool) []refs.ContainerID {
|
|
|
|
var res []refs.ContainerID
|
2021-06-11 12:41:36 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if !empty {
|
|
|
|
res = append(res,
|
2022-03-02 08:18:59 +00:00
|
|
|
*GenerateContainerID(false),
|
|
|
|
*GenerateContainerID(false),
|
2021-03-12 12:57:23 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-06-11 12:41:36 +00:00
|
|
|
return res
|
2021-03-12 12:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateSignature(empty bool) *refs.Signature {
|
|
|
|
m := new(refs.Signature)
|
|
|
|
|
|
|
|
if !empty {
|
2024-08-26 11:13:20 +00:00
|
|
|
key := make([]byte, 33)
|
|
|
|
_, _ = crand.Read(key)
|
|
|
|
|
|
|
|
sign := make([]byte, 65)
|
|
|
|
_, _ = crand.Read(sign)
|
|
|
|
|
|
|
|
m.SetScheme(refs.ECDSA_SHA512)
|
|
|
|
m.SetKey(key)
|
|
|
|
m.SetSign(sign)
|
2021-03-12 12:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateChecksum(empty bool) *refs.Checksum {
|
|
|
|
m := new(refs.Checksum)
|
|
|
|
|
|
|
|
if !empty {
|
2024-08-26 11:13:20 +00:00
|
|
|
cs := make([]byte, sha256.Size)
|
|
|
|
_, _ = crand.Read(cs)
|
|
|
|
|
|
|
|
m.SetType(refs.SHA256)
|
|
|
|
m.SetSum(cs)
|
2021-03-12 12:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|