space monkey internal commit export

[katamari commit: a787e0a0c25fd8ad187772370e3c7272418f6ef8]
This commit is contained in:
JT Olds 2014-02-28 14:24:02 -07:00
parent 6993541398
commit 9038b3bfc8
4 changed files with 23 additions and 2 deletions

6
bio.go
View File

@ -283,6 +283,9 @@ type anyBio C.BIO
func asAnyBio(b *C.BIO) *anyBio { return (*anyBio)(b) } func asAnyBio(b *C.BIO) *anyBio { return (*anyBio)(b) }
func (b *anyBio) Read(buf []byte) (n int, err error) { func (b *anyBio) Read(buf []byte) (n int, err error) {
if len(buf) == 0 {
return 0, nil
}
n = int(C.BIO_read((*C.BIO)(b), unsafe.Pointer(&buf[0]), C.int(len(buf)))) n = int(C.BIO_read((*C.BIO)(b), unsafe.Pointer(&buf[0]), C.int(len(buf))))
if n <= 0 { if n <= 0 {
return 0, io.EOF return 0, io.EOF
@ -291,6 +294,9 @@ func (b *anyBio) Read(buf []byte) (n int, err error) {
} }
func (b *anyBio) Write(buf []byte) (written int, err error) { func (b *anyBio) Write(buf []byte) (written int, err error) {
if len(buf) == 0 {
return 0, nil
}
n := int(C.BIO_write((*C.BIO)(b), unsafe.Pointer(&buf[0]), n := int(C.BIO_write((*C.BIO)(b), unsafe.Pointer(&buf[0]),
C.int(len(buf)))) C.int(len(buf))))
if n != len(buf) { if n != len(buf) {

View File

@ -316,6 +316,9 @@ func (c *Conn) Close() error {
} }
func (c *Conn) read(b []byte) (int, func() error) { func (c *Conn) read(b []byte) (int, func() error) {
if len(b) == 0 {
return 0, nil
}
c.mtx.Lock() c.mtx.Lock()
defer c.mtx.Unlock() defer c.mtx.Unlock()
if c.is_shutdown { if c.is_shutdown {
@ -353,6 +356,9 @@ func (c *Conn) Read(b []byte) (n int, err error) {
} }
func (c *Conn) write(b []byte) (int, func() error) { func (c *Conn) write(b []byte) (int, func() error) {
if len(b) == 0 {
return 0, nil
}
c.mtx.Lock() c.mtx.Lock()
defer c.mtx.Unlock() defer c.mtx.Unlock()
if c.is_shutdown { if c.is_shutdown {

7
ctx.go
View File

@ -268,8 +268,11 @@ func (c *Ctx) SetVerifyDepth(depth int) {
func (c *Ctx) SetSessionId(session_id []byte) error { func (c *Ctx) SetSessionId(session_id []byte) error {
runtime.LockOSThread() runtime.LockOSThread()
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
if int(C.SSL_CTX_set_session_id_context(c.ctx, var ptr *C.uchar
(*C.uchar)(unsafe.Pointer(&session_id[0])), if len(session_id) > 0 {
ptr = (*C.uchar)(unsafe.Pointer(&session_id[0]))
}
if int(C.SSL_CTX_set_session_id_context(c.ctx, ptr,
C.uint(len(session_id)))) == 0 { C.uint(len(session_id)))) == 0 {
return errorFromErrorQueue() return errorFromErrorQueue()
} }

6
pem.go
View File

@ -119,6 +119,9 @@ func (key *pKey) MarshalPKIXPublicKeyDER() (der_block []byte,
// LoadPrivateKey loads a private key from a PEM-encoded block. // LoadPrivateKey loads a private key from a PEM-encoded block.
func LoadPrivateKey(pem_block []byte) (PrivateKey, error) { func LoadPrivateKey(pem_block []byte) (PrivateKey, error) {
if len(pem_block) == 0 {
return nil, errors.New("empty pem block")
}
bio := C.BIO_new_mem_buf(unsafe.Pointer(&pem_block[0]), bio := C.BIO_new_mem_buf(unsafe.Pointer(&pem_block[0]),
C.int(len(pem_block))) C.int(len(pem_block)))
if bio == nil { if bio == nil {
@ -155,6 +158,9 @@ type Certificate struct {
// LoadCertificate loads an X509 certificate from a PEM-encoded block. // LoadCertificate loads an X509 certificate from a PEM-encoded block.
func LoadCertificate(pem_block []byte) (*Certificate, error) { func LoadCertificate(pem_block []byte) (*Certificate, error) {
if len(pem_block) == 0 {
return nil, errors.New("empty pem block")
}
runtime.LockOSThread() runtime.LockOSThread()
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
bio := C.BIO_new_mem_buf(unsafe.Pointer(&pem_block[0]), bio := C.BIO_new_mem_buf(unsafe.Pointer(&pem_block[0]),