Skip to content

Commit ade15fd

Browse files
committed
Fix decoding unsigned long arrays
1 parent 8723f32 commit ade15fd

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

coder.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,22 @@ func DecodeAttribute(data []byte) C.CK_ATTRIBUTE {
300300
attribute.pValue = C.CK_VOID_PTR(unsafe.SliceData(value))
301301
} else if valueType.Elem() == reflect.TypeOf(*new(C.CK_MECHANISM_TYPE)) {
302302
value := remaining[4 : 4+attribute.ulValueLen]
303-
attribute.pValue = C.CK_VOID_PTR(unsafe.SliceData(value))
303+
arrayBuffer := bytes.NewBuffer(value)
304+
305+
mechanismTypeArray := make([]C.CK_MECHANISM_TYPE, attribute.ulValueLen/8)
306+
for i := 0; i < len(ulongArray); i++ {
307+
mechanismTypeArray[i] = DecodeUnsignedLong(arrayBuffer.Next(8))
308+
}
309+
attribute.pValue = C.CK_VOID_PTR(unsafe.SliceData(mechanismTypeArray))
304310
} else if valueType.Elem() == reflect.TypeOf(*new(C.CK_ULONG)) {
305311
value := remaining[4 : 4+attribute.ulValueLen]
306-
attribute.pValue = C.CK_VOID_PTR(unsafe.SliceData(value))
312+
arrayBuffer := bytes.NewBuffer(value)
313+
314+
ulongArray := make([]C.CK_ULONG, attribute.ulValueLen/8)
315+
for i := 0; i < len(ulongArray); i++ {
316+
ulongArray[i] = DecodeUnsignedLong(arrayBuffer.Next(8))
317+
}
318+
attribute.pValue = C.CK_VOID_PTR(unsafe.SliceData(ulongArray))
307319
} else if valueType.Elem() == reflect.TypeOf(*new(C.CK_UTF8CHAR)) {
308320
value := remaining[4 : 4+attribute.ulValueLen]
309321
attribute.pValue = C.CK_VOID_PTR(unsafe.SliceData(value))

0 commit comments

Comments
 (0)