From 43e530dce9a3833c7fdcbf527b757581e5e37657 Mon Sep 17 00:00:00 2001 From: Michael Grosshans Date: Tue, 3 Jan 2017 16:34:35 +0100 Subject: Fixed String Decoding --- ber.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'ber.go') diff --git a/ber.go b/ber.go index 3e99a27..5f95e0a 100644 --- a/ber.go +++ b/ber.go @@ -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) { -- cgit v1.2.3 From e8fcb80412352832e63f8a5859687729d358461b Mon Sep 17 00:00:00 2001 From: Michael Grosshans Date: Wed, 4 Jan 2017 15:23:38 +0100 Subject: Fixed problem with message 128 --- ber.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'ber.go') diff --git a/ber.go b/ber.go index 5f95e0a..95755fe 100644 --- a/ber.go +++ b/ber.go @@ -290,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 { -- cgit v1.2.3