示例#1
0
文件: rand.go 项目: runcom/gossl
func (r *reader) Read(p []byte) (n int, err error) {
	var (
		p_len          = len(p)
		buf   *C.uchar = (*C.uchar)(C.malloc(C.size_t(p_len)))
	)
	defer C.free(unsafe.Pointer(buf))

	if C.RAND_bytes(buf, C.int(p_len)) == 1 {
		copy(p, C.GoBytes(unsafe.Pointer(buf), C.int(p_len)))
		return len(p), nil
	}
	return 0, sslerr.Error()
}
示例#2
0
文件: rand.go 项目: partkyle/gossl
func (r *reader) Read(p []byte) (n int, err error) {
	var (
		p_len          = len(p)
		buf   *C.uchar = (*C.uchar)(C.malloc(C.size_t(p_len)))
	)
	defer C.free(unsafe.Pointer(buf))

	if C.RAND_bytes(buf, C.int(p_len)) == 1 {
		copy(p, C.GoBytes(unsafe.Pointer(buf), C.int(p_len)))
		return len(p), nil
	}
	//return 0, errors.New("farts") // TODO read the error from SSL
	return 0, errors.New(sslerr.SSLErrorMessage())
}