...

Source file src/cuelabs.dev/go/oci/ociregistry/valid.go

Documentation: cuelabs.dev/go/oci/ociregistry

     1  package ociregistry
     2  
     3  import (
     4  	"regexp"
     5  
     6  	"github.com/opencontainers/go-digest"
     7  )
     8  
     9  var (
    10  	tagPattern      = regexp.MustCompile(`^[a-zA-Z0-9_][a-zA-Z0-9._-]{0,127}$`)
    11  	repoNamePattern = regexp.MustCompile(`^[a-z0-9]+([._-][a-z0-9]+)*(/[a-z0-9]+([._-][a-z0-9]+)*)*$`)
    12  )
    13  
    14  // IsValidRepoName reports whether the given repository
    15  // name is valid according to the specification.
    16  func IsValidRepoName(repoName string) bool {
    17  	return repoNamePattern.MatchString(repoName)
    18  }
    19  
    20  // IsValidTag reports whether the digest d is valid
    21  // according to the specification.
    22  func IsValidTag(tag string) bool {
    23  	return tagPattern.MatchString(tag)
    24  }
    25  
    26  // IsValidDigest reports whether the digest d is well formed.
    27  func IsValidDigest(d string) bool {
    28  	_, err := digest.Parse(d)
    29  	return err == nil
    30  }
    31  

View as plain text