|
1 | 1 | package ldap
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "encoding/asn1" |
5 | 4 | "encoding/hex"
|
6 | 5 | "errors"
|
7 | 6 | "fmt"
|
| 7 | + ber "github.com/go-asn1-ber/asn1-ber" |
8 | 8 | "sort"
|
9 | 9 | "strings"
|
10 | 10 | "unicode"
|
@@ -35,9 +35,6 @@ func (a *AttributeTypeAndValue) setValue(s string) error {
|
35 | 35 | // AttributeValue is represented by an number sign ('#' U+0023)
|
36 | 36 | // character followed by the hexadecimal encoding of each of the octets
|
37 | 37 | // of the BER encoding of the X.500 AttributeValue.
|
38 |
| - // |
39 |
| - // WARNING: we only support hex-encoded ASN.1 DER values here, not |
40 |
| - // BER encoding. This is a deviation from the RFC. |
41 | 38 | if len(s) > 0 && s[0] == '#' {
|
42 | 39 | decodedString, err := decodeEncodedString(s[1:])
|
43 | 40 | if err != nil {
|
@@ -233,19 +230,15 @@ func encodeString(value string, isValue bool) string {
|
233 | 230 | func decodeEncodedString(str string) (string, error) {
|
234 | 231 | decoded, err := hex.DecodeString(str)
|
235 | 232 | if err != nil {
|
236 |
| - return "", fmt.Errorf("failed to decode BER encoding: %s", err) |
| 233 | + return "", fmt.Errorf("failed to decode BER encoding: %w", err) |
237 | 234 | }
|
238 | 235 |
|
239 |
| - var rawValue asn1.RawValue |
240 |
| - result, err := asn1.Unmarshal(decoded, &rawValue) |
| 236 | + packet, err := ber.DecodePacketErr(decoded) |
241 | 237 | if err != nil {
|
242 |
| - return "", fmt.Errorf("failed to unmarshal hex-encoded string: %s", err) |
243 |
| - } |
244 |
| - if len(result) != 0 { |
245 |
| - return "", errors.New("trailing data after unmarshalling hex-encoded string") |
| 238 | + return "", fmt.Errorf("failed to decode BER encoding: %w", err) |
246 | 239 | }
|
247 | 240 |
|
248 |
| - return string(rawValue.Bytes), nil |
| 241 | + return packet.Data.String(), nil |
249 | 242 | }
|
250 | 243 |
|
251 | 244 | // ParseDN returns a distinguishedName or an error.
|
|
0 commit comments