diff options
author | jsing <> | 2015-10-13 12:56:20 +0000 |
---|---|---|
committer | jsing <> | 2015-10-13 12:56:20 +0000 |
commit | a4abefbb1d275afbf70665550417fa7200dd77d8 (patch) | |
tree | d60dc1014dfa6e6c08442318c096bd7907663190 /src | |
parent | 5ff1950dc06c4d15570f0930366ae7ea3620be02 (diff) | |
download | openbsd-a4abefbb1d275afbf70665550417fa7200dd77d8.tar.gz openbsd-a4abefbb1d275afbf70665550417fa7200dd77d8.tar.bz2 openbsd-a4abefbb1d275afbf70665550417fa7200dd77d8.zip |
Make regress work again post hackathon tls_handshake/tls_read/tls_write
changes.
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libtls/gotls/tls.go | 49 |
1 files changed, 42 insertions, 7 deletions
diff --git a/src/regress/lib/libtls/gotls/tls.go b/src/regress/lib/libtls/gotls/tls.go index b3fa9fe857..6dc51b8922 100644 --- a/src/regress/lib/libtls/gotls/tls.go +++ b/src/regress/lib/libtls/gotls/tls.go | |||
@@ -18,6 +18,11 @@ import ( | |||
18 | "unsafe" | 18 | "unsafe" |
19 | ) | 19 | ) |
20 | 20 | ||
21 | var ( | ||
22 | errWantPollIn = errors.New("want poll in") | ||
23 | errWantPollOut = errors.New("want poll out") | ||
24 | ) | ||
25 | |||
21 | // TLSConfig provides configuration options for a TLS context. | 26 | // TLSConfig provides configuration options for a TLS context. |
22 | type TLSConfig struct { | 27 | type TLSConfig struct { |
23 | caFile *C.char | 28 | caFile *C.char |
@@ -127,29 +132,59 @@ func (t *TLS) Connect(host, port string) error { | |||
127 | return nil | 132 | return nil |
128 | } | 133 | } |
129 | 134 | ||
135 | // Handshake attempts to complete the TLS handshake. | ||
136 | func (t *TLS) Handshake() error { | ||
137 | ret := C.tls_handshake(t.ctx) | ||
138 | switch { | ||
139 | case ret == C.TLS_WANT_POLLIN: | ||
140 | return errWantPollIn | ||
141 | case ret == C.TLS_WANT_POLLOUT: | ||
142 | return errWantPollOut | ||
143 | case ret != 0: | ||
144 | return fmt.Errorf("handshake failed: %v", t.Error()) | ||
145 | } | ||
146 | return nil | ||
147 | } | ||
148 | |||
130 | // Read reads data the TLS connection into the given buffer. | 149 | // Read reads data the TLS connection into the given buffer. |
131 | func (t *TLS) Read(buf []byte) (int, error) { | 150 | func (t *TLS) Read(buf []byte) (int, error) { |
132 | var inlen C.size_t | 151 | ret := C.tls_read(t.ctx, unsafe.Pointer(&buf[0]), C.size_t(len(buf))) |
133 | if C.tls_read(t.ctx, unsafe.Pointer(&buf[0]), C.size_t(len(buf)), (*C.size_t)(unsafe.Pointer(&inlen))) != 0 { | 152 | switch { |
153 | case ret == C.TLS_WANT_POLLIN: | ||
154 | return -1, errWantPollIn | ||
155 | case ret == C.TLS_WANT_POLLOUT: | ||
156 | return -1, errWantPollOut | ||
157 | case ret < 0: | ||
134 | return -1, fmt.Errorf("read failed: %v", t.Error()) | 158 | return -1, fmt.Errorf("read failed: %v", t.Error()) |
135 | } | 159 | } |
136 | return int(inlen), nil | 160 | return int(ret), nil |
137 | } | 161 | } |
138 | 162 | ||
139 | // Write writes the given data to the TLS connection. | 163 | // Write writes the given data to the TLS connection. |
140 | func (t *TLS) Write(buf []byte) (int, error) { | 164 | func (t *TLS) Write(buf []byte) (int, error) { |
141 | var outlen C.size_t | ||
142 | p := C.CString(string(buf)) | 165 | p := C.CString(string(buf)) |
143 | defer C.free(unsafe.Pointer(p)) | 166 | defer C.free(unsafe.Pointer(p)) |
144 | if C.tls_write(t.ctx, unsafe.Pointer(p), C.size_t(len(buf)), (*C.size_t)(unsafe.Pointer(&outlen))) != 0 { | 167 | ret := C.tls_write(t.ctx, unsafe.Pointer(p), C.size_t(len(buf))) |
168 | switch { | ||
169 | case ret == C.TLS_WANT_POLLIN: | ||
170 | return -1, errWantPollIn | ||
171 | case ret == C.TLS_WANT_POLLOUT: | ||
172 | return -1, errWantPollOut | ||
173 | case ret < 0: | ||
145 | return -1, fmt.Errorf("write failed: %v", t.Error()) | 174 | return -1, fmt.Errorf("write failed: %v", t.Error()) |
146 | } | 175 | } |
147 | return int(outlen), nil | 176 | return int(ret), nil |
148 | } | 177 | } |
149 | 178 | ||
150 | // Close closes the TLS connection. | 179 | // Close closes the TLS connection. |
151 | func (t *TLS) Close() error { | 180 | func (t *TLS) Close() error { |
152 | if C.tls_close(t.ctx) != 0 { | 181 | ret := C.tls_close(t.ctx) |
182 | switch { | ||
183 | case ret == C.TLS_WANT_POLLIN: | ||
184 | return errWantPollIn | ||
185 | case ret == C.TLS_WANT_POLLOUT: | ||
186 | return errWantPollOut | ||
187 | case ret != 0: | ||
153 | return fmt.Errorf("close failed: %v", t.Error()) | 188 | return fmt.Errorf("close failed: %v", t.Error()) |
154 | } | 189 | } |
155 | return nil | 190 | return nil |