Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
qingyang-hu committed Aug 24, 2023
1 parent 0a2d5b1 commit b38f4ac
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ functions:
rm -rf libmongocrypt-all
echo "fetching build for Windows ... end"
else
git clone https://github.com/kevinAlbs/libmongocrypt --depth=1 --branch G2872
git clone https://github.com/qingyang-hu/libmongocrypt --depth=1 --branch G2872
# Specify a BUILD_VERSION, since libmongocrypt may not compute the correct build version on a non-tagged commit.
export ADDITIONAL_CMAKE_FLAGS="-DBUILD_VERSION=1.9.0-pre"
if ! ( ./libmongocrypt/.evergreen/compile.sh >| output.txt 2>&1 ); then
Expand Down
14 changes: 9 additions & 5 deletions x/mongo/driver/mongocrypt/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@

package mongocrypt

// #include <mongocrypt.h>
/*
#include <stdlib.h>
#include <mongocrypt.h>
*/
import "C"
import (
"unsafe"
)

// binary is a wrapper type around a mongocrypt_binary_t*
type binary struct {
p *C.uint8_t
wrapped *C.mongocrypt_binary_t
}

Expand All @@ -33,11 +37,10 @@ func newBinaryFromBytes(data []byte) *binary {
return newBinary()
}

// We don't need C.CBytes here because data cannot go out of scope. Any mongocrypt function that takes a
// mongocrypt_binary_t will make a copy of the data so the data can be garbage collected after calling.
addr := (*C.uint8_t)(unsafe.Pointer(&data[0])) // uint8_t*
dataLen := C.uint32_t(len(data)) // uint32_t
addr := (*C.uint8_t)(C.CBytes(data)) // uint8_t*
dataLen := C.uint32_t(len(data)) // uint32_t
return &binary{
p: addr,
wrapped: C.mongocrypt_binary_new_from_data(addr, dataLen),
}
}
Expand All @@ -52,5 +55,6 @@ func (b *binary) toBytes() []byte {

// close cleans up any resources associated with the given binary instance.
func (b *binary) close() {
C.free(unsafe.Pointer(b.p))
C.mongocrypt_binary_destroy(b.wrapped)
}
6 changes: 6 additions & 0 deletions x/mongo/driver/mongocrypt/mongocrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package mongocrypt
import "C"
import (
"context"
"encoding/hex"
"errors"
"fmt"
"net/http"
Expand Down Expand Up @@ -119,6 +120,11 @@ func (m *MongoCrypt) CreateEncryptionContext(db string, cmd bsoncore.Document) (
return nil, m.createErrorFromStatus()
}

if l := len(cmd); l > 16 {
fmt.Println("CreateEncryptionContext", l, hex.EncodeToString(cmd[:16]), hex.EncodeToString(cmd[l-16:]))
} else {
fmt.Println("CreateEncryptionContext", l, hex.EncodeToString(cmd[:]))
}
cmdBinary := newBinaryFromBytes(cmd)
defer cmdBinary.close()
dbStr := C.CString(db)
Expand Down

0 comments on commit b38f4ac

Please sign in to comment.