bifurcation / mint

A Minimal TLS 1.3 Implementation in Go
MIT License
224 stars 36 forks source link

Allow validation at TLS marshal/unmarshal time #215

Closed bifurcation closed 4 years ago

bifurcation commented 4 years ago

For example, with this change, an "enum" type can validate that the value to be encoded or the just-decoded value is a valid enum value, just by defining a single method:

func (e Enum) ValidForTLS() error {
  if (e == KnownEnumValue0) || (e == KnownEnumValue0) || ... {
    return nil
  }
  return fmt.Errorf("Unknown enum value")
}

This facility could also, of course, be used to validate more advanced types.