diff options
Diffstat (limited to 'object/id')
| -rw-r--r-- | object/id/algorithm_details.go | 13 | ||||
| -rw-r--r-- | object/id/algorithm_signatureheadername.go | 6 | ||||
| -rw-r--r-- | object/id/algorithm_tables.go | 19 | ||||
| -rw-r--r-- | object/id/signatureheadername_parse.go | 9 |
4 files changed, 35 insertions, 12 deletions
diff --git a/object/id/algorithm_details.go b/object/id/algorithm_details.go index fbdc3c78..15e96292 100644 --- a/object/id/algorithm_details.go +++ b/object/id/algorithm_details.go @@ -3,12 +3,13 @@ package objectid import "hash" type algorithmDetails struct { - name string - size int - packHashID uint32 - sum func([]byte) ObjectID - new func() hash.Hash - emptyTree ObjectID + name string + size int + packHashID uint32 + signatureHeaderName string + sum func([]byte) ObjectID + new func() hash.Hash + emptyTree ObjectID } func (algo Algorithm) info() algorithmDetails { diff --git a/object/id/algorithm_signatureheadername.go b/object/id/algorithm_signatureheadername.go new file mode 100644 index 00000000..34fa41ce --- /dev/null +++ b/object/id/algorithm_signatureheadername.go @@ -0,0 +1,6 @@ +package objectid + +// SignatureHeaderName returns the signature header name for this algorithm. +func (algo Algorithm) SignatureHeaderName() string { + return algo.info().signatureHeaderName +} diff --git a/object/id/algorithm_tables.go b/object/id/algorithm_tables.go index 2ea85879..92b77de0 100644 --- a/object/id/algorithm_tables.go +++ b/object/id/algorithm_tables.go @@ -9,9 +9,10 @@ import ( var algorithmTable = [...]algorithmDetails{ AlgorithmUnknown: {}, AlgorithmSHA1: { - name: "sha1", - size: sha1.Size, - packHashID: 1, + name: "sha1", + size: sha1.Size, + packHashID: 1, + signatureHeaderName: "gpgsig", sum: func(data []byte) ObjectID { sum := sha1.Sum(data) //#nosec G401 @@ -24,9 +25,10 @@ var algorithmTable = [...]algorithmDetails{ new: sha1.New, }, AlgorithmSHA256: { - name: "sha256", - size: sha256.Size, - packHashID: 2, + name: "sha256", + size: sha256.Size, + packHashID: 2, + signatureHeaderName: "gpgsig-sha256", sum: func(data []byte) ObjectID { sum := sha256.Sum256(data) @@ -44,6 +46,8 @@ var ( //nolint:gochecknoglobals algorithmByName = map[string]Algorithm{} //nolint:gochecknoglobals + algorithmBySignatureHeaderName = map[string]Algorithm{} + //nolint:gochecknoglobals supportedAlgorithms []Algorithm ) @@ -58,6 +62,9 @@ func init() { //nolint:gochecknoinits info.emptyTree = info.sum(emptyTreeInput) algorithmByName[info.name] = algo + if info.signatureHeaderName != "" { + algorithmBySignatureHeaderName[info.signatureHeaderName] = algo + } supportedAlgorithms = append(supportedAlgorithms, algo) } } diff --git a/object/id/signatureheadername_parse.go b/object/id/signatureheadername_parse.go new file mode 100644 index 00000000..dbe0636a --- /dev/null +++ b/object/id/signatureheadername_parse.go @@ -0,0 +1,9 @@ +package objectid + +// ParseSignatureHeaderName parses one canonical signature header name such as +// "gpgsig" or "gpgsig-sha256". +func ParseSignatureHeaderName(s string) (Algorithm, bool) { + algo, ok := algorithmBySignatureHeaderName[s] + + return algo, ok +} |
