Skip to content

Commit 4f87ad6

Browse files
committed
fix aes test
1 parent 51c7f68 commit 4f87ad6

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

aes_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build cgo
2-
31
package openssl_test
42

53
import (

openssl_cgo.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ func goString(ptr *byte) string {
3838

3939
// goBytes converts a C byte array to a Go byte slice for cgo mode
4040
func goBytes(ptr unsafe.Pointer, length int) []byte {
41-
if ptr == nil || length == 0 {
42-
return nil
43-
}
44-
return unsafe.Slice((*byte)(ptr), length)
41+
return C.GoBytes(ptr, C.int(length))
4542
}
4643

4744
// isProviderAvailable checks if the provider with the given name is available.

openssl_nocgo.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ func goBytes(ptr unsafe.Pointer, length int) []byte {
2929
if ptr == nil || length == 0 {
3030
return nil
3131
}
32-
return unsafe.Slice((*byte)(ptr), length)
32+
// Copy the data to Go memory, similar to C.GoBytes
33+
result := make([]byte, length)
34+
copy(result, unsafe.Slice((*byte)(ptr), length))
35+
return result
3336
}
3437

3538
// VersionText returns the version text of the OpenSSL currently loaded.

0 commit comments

Comments
 (0)