@@ -51,15 +51,12 @@ package simulator
5151
5252import (
5353 "bytes"
54- "crypto"
55- "crypto/ed25519"
5654 "crypto/sha256"
5755 "fmt"
5856 "log/slog"
5957 "net/url"
6058 "os"
6159 "path/filepath"
62- "regexp"
6360 "strconv"
6461 "strings"
6562 "time"
@@ -161,7 +158,7 @@ func (rs *RepositorySimulator) setupMinimalValidRepository() {
161158 rs .MDRoot = metadata .Root (rs .SafeExpiry )
162159
163160 for _ , role := range metadata .TOP_LEVEL_ROLE_NAMES {
164- publicKey , _ , signer := CreateKey ()
161+ publicKey , _ , signer := createKey ()
165162
166163 mtdkey , err := metadata .KeyFromPublicKey (* publicKey )
167164 if err != nil {
@@ -212,20 +209,6 @@ func (rs *RepositorySimulator) AllTargets() <-chan metadata.TargetsType {
212209 return ch
213210}
214211
215- func CreateKey () (* ed25519.PublicKey , * ed25519.PrivateKey , * signature.Signer ) {
216- public , private , err := ed25519 .GenerateKey (nil )
217- if err != nil {
218- slog .Error ("Failed to generate key" , "err" , err )
219- }
220-
221- signer , err := signature .LoadSigner (private , crypto .Hash (0 ))
222- if err != nil {
223- slog .Error ("failed to load signer" , "err" , err )
224- }
225-
226- return & public , & private , & signer
227- }
228-
229212func (rs * RepositorySimulator ) AddSigner (role string , keyID string , signer signature.Signer ) {
230213 if _ , ok := rs .Signers [role ]; ! ok {
231214 rs .Signers [role ] = make (map [string ]* signature.Signer )
@@ -241,7 +224,7 @@ func (rs *RepositorySimulator) RotateKeys(role string) {
241224 }
242225
243226 for i := 0 ; i < rs .MDRoot .Signed .Roles [role ].Threshold ; i ++ {
244- publicKey , _ , signer := CreateKey ()
227+ publicKey , _ , signer := createKey ()
245228 mtdkey , err := metadata .KeyFromPublicKey (* publicKey )
246229 if err != nil {
247230 slog .Error ("Repository simulator: key conversion failed while rotating keys" , "err" , err )
@@ -316,34 +299,6 @@ func (rs *RepositorySimulator) DownloadFile(urlPath string, maxLength int64, _ t
316299 return data , err
317300}
318301
319- func IsWindowsPath (path string ) bool {
320- match , _ := regexp .MatchString (`^[a-zA-Z]:\\` , path )
321- return match
322- }
323-
324- func trimPrefix (path string , prefix string ) (string , error ) {
325- var toTrim string
326- if IsWindowsPath (path ) {
327- toTrim = path
328- } else {
329- parsedURL , e := url .Parse (path )
330- if e != nil {
331- return "" , e
332- }
333- toTrim = parsedURL .Path
334- }
335-
336- return strings .TrimPrefix (toTrim , prefix ), nil
337- }
338-
339- func hasPrefix (path , prefix string ) bool {
340- return strings .HasPrefix (filepath .ToSlash (path ), prefix )
341- }
342-
343- func hasSuffix (path , prefix string ) bool {
344- return strings .HasSuffix (filepath .ToSlash (path ), prefix )
345- }
346-
347302func (rs * RepositorySimulator ) fetch (urlPath string ) ([]byte , error ) {
348303 path , err := trimPrefix (urlPath , rs .LocalDir )
349304 if err != nil {
@@ -552,7 +507,7 @@ func (rs *RepositorySimulator) AddDelegation(delegatorName string, role metadata
552507 delegator .Delegations .Roles = append (delegator .Delegations .Roles , role )
553508
554509 // By default add one new key for the role
555- publicKey , _ , signer := CreateKey ()
510+ publicKey , _ , signer := createKey ()
556511 mdkey , err := metadata .KeyFromPublicKey (* publicKey )
557512 if err != nil {
558513 slog .Error ("Repository simulator: key conversion failed while adding delegation" , "err" , err )
@@ -580,7 +535,7 @@ func (rs *RepositorySimulator) AddSuccinctRoles(delegatorName string, bitLength
580535 slog .Error ("Can't add a SuccinctRoles when delegated roles are used" )
581536 os .Exit (1 )
582537 }
583- publicKey , _ , signer := CreateKey ()
538+ publicKey , _ , signer := createKey ()
584539 mdkey , err := metadata .KeyFromPublicKey (* publicKey )
585540 if err != nil {
586541 slog .Error ("Repository simulator: key conversion failed while adding succinct roles" , "err" , err )
0 commit comments