Skip to content

Commit f159972

Browse files
committed
identifier: Rename FromDNSNames & AsProto; add ACMEIdentifiers named type
Rename `FromDNSNames` to `NewDNSSlice`, since it's exactly `NewDNS` except for slices. Rename `AsProto` to use the "To" prefix, since it's the opposite of "From". Add a named type `ACMEIdentifiers` so that we can add methods to slices. We will have a lot of slice handling code coming up, which this will make more elegant and readable. Add a comment to explain naming conventions in the `identiifer` package. Part of #7311 Alternative to #8068
1 parent 6071bed commit f159972

File tree

6 files changed

+18
-9
lines changed

6 files changed

+18
-9
lines changed

csr/csr.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func VerifyCSR(ctx context.Context, csr *x509.CertificateRequest, maxNames int,
8282
return berrors.BadCSRError("CSR contains more than %d DNS names", maxNames)
8383
}
8484

85-
err = pa.WillingToIssue(identifier.FromDNSNames(names.SANs))
85+
err = pa.WillingToIssue(identifier.NewDNSSlice(names.SANs))
8686
if err != nil {
8787
return err
8888
}

identifier/identifier.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// The identifier package defines types for RFC 8555 ACME identifiers.
2+
//
23
// It exists as a separate package to prevent an import loop between the core
34
// and probs packages.
5+
//
6+
// Function naming conventions:
7+
// - "New" creates a new instance from one or more simple base type inputs.
8+
// - "From" and "To" extract information from, or compose, a more complex object.
49
package identifier
510

611
import (
@@ -32,7 +37,11 @@ type ACMEIdentifier struct {
3237
Value string `json:"value"`
3338
}
3439

35-
func (i ACMEIdentifier) AsProto() *corepb.Identifier {
40+
// ACMEIdentifiers is a named type for a slice of ACME identifiers, so that
41+
// methods can be applied to these slices.
42+
type ACMEIdentifiers []ACMEIdentifier
43+
44+
func (i ACMEIdentifier) ToProto() *corepb.Identifier {
3645
return &corepb.Identifier{
3746
Type: string(i.Type),
3847
Value: i.Value,
@@ -64,9 +73,9 @@ func NewDNS(domain string) ACMEIdentifier {
6473
}
6574
}
6675

67-
// FromDNSNames is a convenience function for creating a slice of ACMEIdentifier
76+
// NewDNSSlice is a convenience function for creating a slice of ACMEIdentifier
6877
// with Type "dns" for a given slice of domain names.
69-
func FromDNSNames(input []string) []ACMEIdentifier {
78+
func NewDNSSlice(input []string) ACMEIdentifiers {
7079
var out []ACMEIdentifier
7180
for _, in := range input {
7281
out = append(out, NewDNS(in))

ra/ra.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2281,7 +2281,7 @@ func (ra *RegistrationAuthorityImpl) NewOrder(ctx context.Context, req *rapb.New
22812281
}
22822282

22832283
// Validate that our policy allows issuing for each of the names in the order
2284-
err = ra.PA.WillingToIssue(identifier.FromDNSNames(newOrder.DnsNames))
2284+
err = ra.PA.WillingToIssue(identifier.NewDNSSlice(newOrder.DnsNames))
22852285
if err != nil {
22862286
return nil, err
22872287
}
@@ -2435,7 +2435,7 @@ func (ra *RegistrationAuthorityImpl) NewOrder(ctx context.Context, req *rapb.New
24352435
}
24362436

24372437
newAuthzs = append(newAuthzs, &sapb.NewAuthzRequest{
2438-
Identifier: ident.AsProto(),
2438+
Identifier: ident.ToProto(),
24392439
RegistrationID: newOrder.RegistrationID,
24402440
Expires: timestamppb.New(ra.clk.Now().Add(profile.pendingAuthzLifetime).Truncate(time.Second)),
24412441
ChallengeTypes: challStrs,

ratelimits/names.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func validateFQDNSet(id string) error {
200200
return fmt.Errorf(
201201
"invalid fqdnSet, %q must be formatted 'fqdnSet'", id)
202202
}
203-
return policy.WellFormedIdentifiers(identifier.FromDNSNames(domains))
203+
return policy.WellFormedIdentifiers(identifier.NewDNSSlice(domains))
204204
}
205205

206206
func validateIdForName(name Name, id string) error {

va/va_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ var accountURIPrefixes = []string{"http://boulder.service.consul:4000/acme/reg/"
8585

8686
func createValidationRequest(ident identifier.ACMEIdentifier, challengeType core.AcmeChallenge) *vapb.PerformValidationRequest {
8787
return &vapb.PerformValidationRequest{
88-
Identifier: ident.AsProto(),
88+
Identifier: ident.ToProto(),
8989
Challenge: &corepb.Challenge{
9090
Type: string(challengeType),
9191
Status: string(core.StatusPending),

wfe2/wfe.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2298,7 +2298,7 @@ func (wfe *WebFrontEndImpl) NewOrder(
22982298
}
22992299

23002300
names = core.UniqueLowerNames(names)
2301-
err = policy.WellFormedIdentifiers(identifier.FromDNSNames(names))
2301+
err = policy.WellFormedIdentifiers(identifier.NewDNSSlice(names))
23022302
if err != nil {
23032303
wfe.sendError(response, logEvent, web.ProblemDetailsForError(err, "Invalid identifiers requested"), nil)
23042304
return

0 commit comments

Comments
 (0)