@@ -126,23 +126,22 @@ func (o *OID) UnmarshalText(text []byte) error {
126
126
// reject such encodings.
127
127
for _ , c := range oid {
128
128
isDigit := c >= '0' && c <= '9'
129
- if ! isDigit && c != ' ' && c != ' .' {
129
+ if ! isDigit && c != '.' {
130
130
return errInvalidOID
131
131
}
132
132
}
133
133
134
- end := strings . IndexByte ( oid , '.' )
135
- if end == - 1 {
136
- return errInvalidOID
137
- }
134
+ var (
135
+ firstNum string
136
+ secondNum string
137
+ )
138
138
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
144
143
}
145
- secondNum := oid [: end ]
144
+ secondNum , oid , nextComponentExists = strings . Cut ( oid , "." )
146
145
147
146
var (
148
147
first = big .NewInt (0 )
@@ -165,25 +164,14 @@ func (o *OID) UnmarshalText(text []byte) error {
165
164
166
165
der := appendBase128BigInt (make ([]byte , 0 , 32 ), firstComponent )
167
166
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
186
173
}
174
+ der = appendBase128BigInt (der , b )
187
175
}
188
176
189
177
o .der = der
0 commit comments