fix(varsig): make generic and name decode everywhere

This commit is contained in:
Steve Moyer
2025-07-07 08:55:43 -04:00
parent 9c83def9e0
commit f9f39d363f
3 changed files with 27 additions and 27 deletions

View File

@@ -13,23 +13,23 @@ const (
Version1 Version = 1
)
// ParseFunc is a function that parses the varsig representing a specific
// DecodeFunc is a function that parses the varsig representing a specific
// signing algorithm.
type ParseFunc func(*bytes.Reader, Version, SignAlgorithm) (Varsig, error)
type DecodeFunc func(*bytes.Reader, Version, SignAlgorithm) (Varsig, error)
// Registry contains a mapping between known signing algorithms, and
// functions that can parse varsigs for that signing algorithm.
type Registry map[SignAlgorithm]ParseFunc
type Registry map[SignAlgorithm]DecodeFunc
// DefaultRegistry provides a Registry containing the mappings for the
// signing algorithms which have an implementation within this library.
func DefaultRegistry() Registry {
return map[SignAlgorithm]ParseFunc{
SignAlgorithmRSA: parseRSA,
SignAlgorithmEd25519: notYetImplementedVarsigParser,
SignAlgorithmECDSAP256: notYetImplementedVarsigParser,
SignAlgorithmECDSASecp256k1: notYetImplementedVarsigParser,
SignAlgorithmECDSAP521: notYetImplementedVarsigParser,
return map[SignAlgorithm]DecodeFunc{
SignAlgorithmRSA: decodeRSA,
SignAlgorithmEd25519: notYetImplementedVarsigDecoder,
SignAlgorithmECDSAP256: notYetImplementedVarsigDecoder,
SignAlgorithmECDSASecp256k1: notYetImplementedVarsigDecoder,
SignAlgorithmECDSAP521: notYetImplementedVarsigDecoder,
}
}
@@ -40,8 +40,8 @@ func NewRegistry() Registry {
// Register allows new mappings between a signing algorithm and its parsing
// function to the Registry.
func (rs Registry) Register(alg SignAlgorithm, parseFn ParseFunc) {
rs[alg] = parseFn
func (rs Registry) Register(alg SignAlgorithm, decodeFunc DecodeFunc) {
rs[alg] = decodeFunc
}
// Decode converts the provided data into one of the registered Varsig
@@ -62,20 +62,20 @@ func (rs Registry) DecodeStream(r *bytes.Reader) (Varsig, error) {
return nil, fmt.Errorf("%w: expected %d, got %d", ErrBadPrefix, Prefix, pre)
}
vers, signAlg, err := rs.parseVersAndSignAlg(r)
vers, signAlg, err := rs.decodeVersAndSignAlg(r)
if err != nil {
return nil, err
}
parseFn, ok := rs[SignAlgorithm(signAlg)]
decodeFunc, ok := rs[SignAlgorithm(signAlg)]
if !ok {
return nil, fmt.Errorf("%w: %x", ErrUnknownSignAlgorithm, signAlg)
}
return parseFn(r, vers, signAlg)
return decodeFunc(r, vers, signAlg)
}
func (rs Registry) parseVersAndSignAlg(r *bytes.Reader) (Version, SignAlgorithm, error) {
func (rs Registry) decodeVersAndSignAlg(r *bytes.Reader) (Version, SignAlgorithm, error) {
vers, err := binary.ReadUvarint(r)
if err != nil {
return Version(vers), 0, err
@@ -94,6 +94,6 @@ func (rs Registry) parseVersAndSignAlg(r *bytes.Reader) (Version, SignAlgorithm,
return Version(vers), SignAlgorithm(signAlg), err
}
func notYetImplementedVarsigParser(_ *bytes.Reader, vers Version, signAlg SignAlgorithm) (Varsig, error) {
func notYetImplementedVarsigDecoder(_ *bytes.Reader, vers Version, signAlg SignAlgorithm) (Varsig, error) {
return nil, fmt.Errorf("%w: Version: %d, SignAlgorithm: %x", ErrNotYetImplemented, vers, signAlg)
}