mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
747f89cd32
This introduces Versions for TarSum checksums. Fixes: https://github.com/docker/docker/issues/7526 It preserves current functionality and abstracts the interface for future flexibility of hashing algorithms. As a POC, the VersionDev Tarsum does not include the mtime in the checksum calculation, and would solve https://github.com/docker/docker/issues/7387 though this is not a settled Version is subject to change until a version number is assigned. Signed-off-by: Vincent Batts <vbatts@redhat.com>
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package tarsum
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
)
|
|
|
|
// versioning of the TarSum algorithm
|
|
// based on the prefix of the hash used
|
|
// i.e. "tarsum+sha256:e58fcf7418d4390dec8e8fb69d88c06ec07039d651fedd3aa72af9972e7d046b"
|
|
type Version int
|
|
|
|
const (
|
|
// Prefix of "tarsum"
|
|
Version0 Version = iota
|
|
// Prefix of "tarsum.dev"
|
|
// NOTE: this variable will be of an unsettled next-version of the TarSum calculation
|
|
VersionDev
|
|
)
|
|
|
|
// Get a list of all known tarsum Version
|
|
func GetVersions() []Version {
|
|
v := []Version{}
|
|
for k := range tarSumVersions {
|
|
v = append(v, k)
|
|
}
|
|
return v
|
|
}
|
|
|
|
var tarSumVersions = map[Version]string{
|
|
0: "tarsum",
|
|
1: "tarsum.dev",
|
|
}
|
|
|
|
func (tsv Version) String() string {
|
|
return tarSumVersions[tsv]
|
|
}
|
|
|
|
// GetVersionFromTarsum returns the Version from the provided string
|
|
func GetVersionFromTarsum(tarsum string) (Version, error) {
|
|
tsv := tarsum
|
|
if strings.Contains(tarsum, "+") {
|
|
tsv = strings.SplitN(tarsum, "+", 2)[0]
|
|
}
|
|
for v, s := range tarSumVersions {
|
|
if s == tsv {
|
|
return v, nil
|
|
}
|
|
}
|
|
return -1, ErrNotVersion
|
|
}
|
|
|
|
var (
|
|
ErrNotVersion = errors.New("string does not include a TarSum Version")
|
|
ErrVersionNotImplemented = errors.New("TarSum Version is not yet implemented")
|
|
)
|