diff options
author | Ned McClain <ned@appliedtrust.com> | 2017-01-04 16:48:39 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-04 16:48:39 +0100 |
commit | 2661553a04840c556cf4f3cd69fa3332bae84e9d (patch) | |
tree | e70a4cc58e8a27a93b4303d9d0a8b2fe5309fcb4 | |
parent | fix typo (diff) | |
parent | Fixed problem with message 128 (diff) | |
download | asn1-ber-2661553a04840c556cf4f3cd69fa3332bae84e9d.tar asn1-ber-2661553a04840c556cf4f3cd69fa3332bae84e9d.tar.gz asn1-ber-2661553a04840c556cf4f3cd69fa3332bae84e9d.tar.bz2 asn1-ber-2661553a04840c556cf4f3cd69fa3332bae84e9d.tar.lz asn1-ber-2661553a04840c556cf4f3cd69fa3332bae84e9d.tar.xz asn1-ber-2661553a04840c556cf4f3cd69fa3332bae84e9d.tar.zst asn1-ber-2661553a04840c556cf4f3cd69fa3332bae84e9d.zip |
-rw-r--r-- | ber.go | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -255,12 +255,8 @@ func ReadPacket(reader io.Reader) (*Packet, error) { return p, nil } -func DecodeString(data []byte) (ret string) { - for _, c := range data { - ret += fmt.Sprintf("%c", c) - } - - return +func DecodeString(data []byte) (string) { + return string(data) } func DecodeInteger(data []byte) (ret uint64) { @@ -294,7 +290,14 @@ func EncodeInteger(val uint64) []byte { mask = mask >> 8 } - return out.Bytes() + byteSlice := out.Bytes() + + // if first bit in first byte is 1 it is necessary to append a leading 00 byte to make signum clear + // otherwise it happens that a request with messageId => 02 01 80 get response with messageId => 02 04 FF FF FF 80 + if len(byteSlice) > 0 && byteSlice[0]&byte(128) != 0 { + return append([]byte{0x00}, byteSlice...) + } + return byteSlice } func DecodePacket(data []byte) *Packet { |