Example #1
2
func test14838(t *testing.T) {
	data := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
	cData := C.CBytes(data)
	defer C.free(cData)

	if C.check_cbytes((*C.char)(cData), C.size_t(len(data))) == 0 {
		t.Fatalf("mismatched data: expected %v, got %v", data, (*(*[10]byte)(unsafe.Pointer(cData)))[:])
	}
}
Example #2
0
// ParseCert creates certificate context from byte slice
func ParseCert(buf []byte) (res Cert, err error) {
	bufBytes := C.CBytes(buf)
	defer C.free(bufBytes)

	res.pCert = C.CertCreateCertificateContext(C.MY_ENC_TYPE, (*C.BYTE)(bufBytes), C.DWORD(len(buf)))
	if res.pCert == nil {
		err = getErr("Error creating certficate context")
		return
	}
	return
}
Example #3
0
// FindBySubjectId returns slice of certificates that match given subject key ID. If
// ID supplied could not be decoded from string, FindBySubjectId will
// return nil slice
func (s CertStore) FindBySubjectId(thumb string) []Cert {
	bThumb, err := hex.DecodeString(thumb)
	if err != nil {
		return nil
	}
	var hashBlob C.CRYPT_HASH_BLOB
	hashBlob.cbData = C.DWORD(len(bThumb))
	bThumbPtr := C.CBytes(bThumb)
	defer C.free(bThumbPtr)
	hashBlob.pbData = (*C.BYTE)(bThumbPtr)
	return s.findCerts(C.CERT_FIND_KEY_IDENTIFIER, unsafe.Pointer(&hashBlob))
}
Example #4
0
// NewArchiveFromMemory returns new unarr Archive
func NewArchiveFromMemory(b []byte) (a *Archive, err error) {
	a = new(Archive)

	a.stream = C.ar_open_memory(C.CBytes(b), C.size_t(cap(b)))
	if a.stream == nil {
		err = errors.New("unarr: Open memory failed")
		return
	}

	err = a.Open()

	return
}
Example #5
0
// GetBySubjectId returns first certificate in store that match given subject key ID
func (s CertStore) GetBySubjectId(keyId string) (res Cert, err error) {
	bThumb, err := hex.DecodeString(keyId)
	if err != nil {
		return
	}
	var hashBlob C.CRYPT_HASH_BLOB
	hashBlob.cbData = C.DWORD(len(bThumb))
	bThumbPtr := C.CBytes(bThumb)
	defer C.free(bThumbPtr)
	hashBlob.pbData = (*C.BYTE)(bThumbPtr)
	if res.pCert = s.getCert(C.CERT_FIND_KEY_IDENTIFIER, unsafe.Pointer(&hashBlob)); res.pCert == nil {
		err = getErr("Error looking up certificate by subject key id")
		return
	}
	return
}
Example #6
0
File: cgo.go Project: achanda/go
func CgoTests() {
	var c chan bool
	C.f(*(*unsafe.Pointer)(unsafe.Pointer(&c))) // ERROR "embedded pointer"
	C.f(unsafe.Pointer(&c))                     // ERROR "embedded pointer"

	var m map[string]string
	C.f(*(*unsafe.Pointer)(unsafe.Pointer(&m))) // ERROR "embedded pointer"
	C.f(unsafe.Pointer(&m))                     // ERROR "embedded pointer"

	var f func()
	C.f(*(*unsafe.Pointer)(unsafe.Pointer(&f))) // ERROR "embedded pointer"
	C.f(unsafe.Pointer(&f))                     // ERROR "embedded pointer"

	var s []int
	C.f(*(*unsafe.Pointer)(unsafe.Pointer(&s))) // ERROR "embedded pointer"
	C.f(unsafe.Pointer(&s))                     // ERROR "embedded pointer"

	var a [1][]int
	C.f(*(*unsafe.Pointer)(unsafe.Pointer(&a))) // ERROR "embedded pointer"
	C.f(unsafe.Pointer(&a))                     // ERROR "embedded pointer"

	var st struct{ f []int }
	C.f(*(*unsafe.Pointer)(unsafe.Pointer(&st))) // ERROR "embedded pointer"
	C.f(unsafe.Pointer(&st))                     // ERROR "embedded pointer"

	// The following cases are OK.
	var i int
	C.f(*(*unsafe.Pointer)(unsafe.Pointer(&i)))
	C.f(unsafe.Pointer(&i))

	C.f(*(*unsafe.Pointer)(unsafe.Pointer(&s[0])))
	C.f(unsafe.Pointer(&s[0]))

	var a2 [1]int
	C.f(*(*unsafe.Pointer)(unsafe.Pointer(&a2)))
	C.f(unsafe.Pointer(&a2))

	var st2 struct{ i int }
	C.f(*(*unsafe.Pointer)(unsafe.Pointer(&st2)))
	C.f(unsafe.Pointer(&st2))

	C.CBytes([]byte("hello"))
}
Example #7
0
func main() {
	var s = "hello cgo"
	csl := C.CBytes([]byte(s))
	C.print(csl, C.int(len(s)))
	C.free(unsafe.Pointer(csl))
}