Skip to content

Commit 64910a9

Browse files
committed
simplify
Change-Id: I979fc5f0c8d31ae4e1205e579cf83da0f29e2b75
1 parent a47fec6 commit 64910a9

File tree

1 file changed

+17
-29
lines changed

1 file changed

+17
-29
lines changed

src/crypto/x509/oid.go

+17-29
Original file line numberDiff line numberDiff line change
@@ -126,23 +126,22 @@ func (o *OID) UnmarshalText(text []byte) error {
126126
// reject such encodings.
127127
for _, c := range oid {
128128
isDigit := c >= '0' && c <= '9'
129-
if !isDigit && c != ' ' && c != '.' {
129+
if !isDigit && c != '.' {
130130
return errInvalidOID
131131
}
132132
}
133133

134-
end := strings.IndexByte(oid, '.')
135-
if end == -1 {
136-
return errInvalidOID
137-
}
134+
var (
135+
firstNum string
136+
secondNum string
137+
)
138138

139-
firstNum := oid[:end]
140-
oid = oid[end+1:]
141-
end = strings.IndexByte(oid, '.')
142-
if end == -1 {
143-
end = len(oid)
139+
var nextComponentExists bool
140+
firstNum, oid, nextComponentExists = strings.Cut(oid, ".")
141+
if !nextComponentExists {
142+
return errInvalidOID
144143
}
145-
secondNum := oid[:end]
144+
secondNum, oid, nextComponentExists = strings.Cut(oid, ".")
146145

147146
var (
148147
first = big.NewInt(0)
@@ -165,25 +164,14 @@ func (o *OID) UnmarshalText(text []byte) error {
165164

166165
der := appendBase128BigInt(make([]byte, 0, 32), firstComponent)
167166

168-
if end != len(oid) {
169-
oid = oid[end+1:]
170-
for {
171-
end := strings.IndexByte(oid, '.')
172-
if end == -1 {
173-
end = len(oid)
174-
}
175-
176-
b, ok := big.NewInt(0).SetString(oid[:end], 10)
177-
if !ok {
178-
return errInvalidOID
179-
}
180-
der = appendBase128BigInt(der, b)
181-
182-
if end == len(oid) {
183-
break
184-
}
185-
oid = oid[end+1:]
167+
for nextComponentExists {
168+
var strNum string
169+
strNum, oid, nextComponentExists = strings.Cut(oid, ".")
170+
b, ok := big.NewInt(0).SetString(strNum, 10)
171+
if !ok {
172+
return errInvalidOID
186173
}
174+
der = appendBase128BigInt(der, b)
187175
}
188176

189177
o.der = der

0 commit comments

Comments
 (0)