boulder
boulder copied to clipboard
Improve type-safety in the identifiers package
Currently our Identifier type looks like this: https://github.com/letsencrypt/boulder/blob/bef73f3c8b9e233bbb8ec75e08e007d6c274fed9/identifier/identifier.go#L47-L53
This means that:
- Other packages can access and use the
.Valuewithout checking the.Type, potentially leading to cases where an IP address is used where a DNS name is expected, or vice versa; - It's possible to construct an identifier whose
.Typeclaims to be an IP address but whose.Valueis a DNS name, or vice versa; and - IP Addresses are stored and carried around as strings, rather than as
netip.Addrs.
We'd like to replace this with a more type-safe structure, perhaps something like:
type ACMEIdentifier interface {
func ToProto() *corepb.Identifier
func ToJSON() string
}
type DNS struct {
value string
}
type IP struct {
value netip.Addr
}
where the latter two types implement the interface.