@@ -22,6 +22,7 @@ import (
2222 "strings"
2323 "time"
2424
25+ "github.com/sigstore/rekor/cmd/rekor-cli/app/sharding"
2526 "github.com/sigstore/rekor/pkg/pki"
2627 "github.com/sigstore/rekor/pkg/util"
2728
@@ -56,8 +57,8 @@ var pflagValueFuncMap map[FlagType]newPFlagValueFunc
5657func initializePFlagMap () {
5758 pflagValueFuncMap = map [FlagType ]newPFlagValueFunc {
5859 uuidFlag : func () pflag.Value {
59- // this corresponds to the merkle leaf hash of entries, which is represented by a 64 character hexadecimal string
60- return valueFactory (uuidFlag , validateString ( "required,len=64,hexadecimal" ) , "" )
60+ // this corresponds to the merkle leaf hash of entries, which is represented by a 64 character hexadecimal string, prepended by the 6-digit shard ID and '-' separator
61+ return valueFactory (uuidFlag , validateFullID , "" )
6162 },
6263 shaFlag : func () pflag.Value {
6364 // this validates a valid sha256 checksum which is optionally prefixed with 'sha256:'
@@ -190,6 +191,53 @@ func validateFileOrURL(v string) error {
190191 return valGen ().Set (v )
191192}
192193
194+ // validateFullID ensures the FullID is composed of a valid shardID, separator character, and UUID
195+ func validateFullID (v string ) error {
196+ if len (v ) == sharding .FullIDLen {
197+
198+ // validate separator
199+ if string (v [sharding .ShardIDLen ]) != sharding .FullIDSeparator {
200+ return fmt .Errorf ("unexpected separator char in fullID: %v" , v [sharding .ShardIDLen ])
201+ }
202+
203+ // validate the ShardID
204+ shardID := v [:sharding .ShardIDLen ]
205+ shardIDTag := "required," + "len=" + fmt .Sprintf ("%v" , sharding .ShardIDLen ) + ",number"
206+ shardIDStringValidatorFunc := validateString (shardIDTag )
207+ shardIDErr := shardIDStringValidatorFunc (shardID )
208+
209+ if shardIDErr != nil {
210+ return fmt .Errorf ("invalid shardID: %v" , shardID )
211+ }
212+
213+ // validate the UUID
214+ UUID := v [sharding .FullIDLen - sharding .UUIDLen :]
215+ UUIDTag := "required," + "len=" + fmt .Sprintf ("%v" , sharding .UUIDLen ) + ",hexadecimal"
216+ UUIDStringValidatorFunc := validateString (UUIDTag )
217+ UUIDErr := UUIDStringValidatorFunc (UUID )
218+
219+ if UUIDErr != nil {
220+ return fmt .Errorf ("invalid uuid: %v" , UUID )
221+ }
222+
223+ return nil
224+
225+ } else if len (v ) == sharding .UUIDLen {
226+ // indicates older UUID format is being used without pre-pended shardID
227+ UUIDStringValidatorFunc := validateString ("required,len=64,hexadecimal" )
228+ UUIDErr := UUIDStringValidatorFunc (v )
229+
230+ if UUIDErr != nil {
231+ return fmt .Errorf ("invalid uuid: %v" , v )
232+ }
233+
234+ return nil
235+
236+ }
237+
238+ return fmt .Errorf ("fullID len error, expected %v but got %v" , sharding .FullIDLen , len (v ))
239+ }
240+
193241// validateLogIndex ensures that the supplied string is a valid log index (integer >= 0)
194242func validateLogIndex (v string ) error {
195243 i , err := strconv .Atoi (v )
0 commit comments