@@ -7,28 +7,72 @@ module Node.HTTP.Secure
7
7
, handshakeTimeout
8
8
, requestCert
9
9
, rejectUnauthorized
10
- , NPNProtocols (..)
10
+
11
+ , NPNProtocols
12
+ , npnProtocolsString
13
+ , npnProtocolsBuffer
14
+ , npnProtocolsUint8Array
15
+ , npnProtocolsStringArray
16
+ , npnProtocolsBufferArray
17
+ , npnProtocolsUint8ArrayArray
11
18
, npnProtocols
12
- , ALPNProtocols (..)
19
+
20
+ , ALPNProtocols
21
+ , alpnProtocolsString
22
+ , alpnProtocolsBuffer
23
+ , alpnProtocolsUint8Array
24
+ , alpnProtocolsStringArray
25
+ , alpnProtocolsBufferArray
26
+ , alpnProtocolsUint8ArrayArray
13
27
, alpnProtocols
28
+
14
29
, sessionTimeout
15
30
, ticketKeys
16
- , PFX (..)
31
+
32
+ , PFX
33
+ , pfxString
34
+ , pfxBuffer
17
35
, pfx
18
- , Key (..)
36
+
37
+ , Key
38
+ , keyString
39
+ , keyBuffer
40
+ , keyStringArray
41
+ , keyBufferArray
19
42
, key
43
+
20
44
, passphrase
21
- , Cert (..)
45
+
46
+ , Cert
47
+ , certString
48
+ , certBuffer
49
+ , certStringArray
50
+ , certBufferArray
22
51
, cert
23
- , CA (..)
52
+
53
+ , CA
54
+ , caString
55
+ , caBuffer
56
+ , caStringArray
57
+ , caBufferArray
24
58
, ca
25
- , CRL (..)
59
+
60
+ , CRL
61
+ , crlString
62
+ , crlBuffer
63
+ , crlStringArray
64
+ , crlBufferArray
26
65
, crl
66
+
27
67
, ciphers
28
68
, honorCipherOrder
29
69
, ecdhCurve
30
- , DHParam (..)
70
+
71
+ , DHParam
72
+ , dhparamString
73
+ , dhparamBuffer
31
74
, dhparam
75
+
32
76
, secureProtocol
33
77
, secureOptions
34
78
, sessionIdContext
@@ -38,11 +82,11 @@ import Prelude
38
82
39
83
import Control.Monad.Eff (Eff )
40
84
import Data.ArrayBuffer.Types (Uint8Array )
41
- import Data.Foreign (Foreign , toForeign )
42
- import Data.Functor.Contravariant (cmap )
85
+ import Data.Foreign (Foreign )
43
86
import Data.Options (Options , Option , options , opt )
44
87
import Node.Buffer (Buffer )
45
88
import Node.HTTP (Request , Response , Server , HTTP )
89
+ import Unsafe.Coerce (unsafeCoerce )
46
90
47
91
-- | The type of HTTPS server options
48
92
data SSLOptions
@@ -62,44 +106,42 @@ rejectUnauthorized = opt "rejectUnauthorized"
62
106
-- | The npnProtocols option can be a String, a Buffer, a Uint8Array, or an
63
107
-- | array of any of those types.
64
108
data NPNProtocols
65
- = NPNProtocolsString String
66
- | NPNProtocolsBuffer Buffer
67
- | NPNProtocolsUint8Array Uint8Array
68
- | NPNProtocolsStringArray (Array String )
69
- | NPNProtocolsBufferArray (Array Buffer )
70
- | NPNProtocolsUint8ArrayArray (Array Uint8Array )
109
+ npnProtocolsString :: String -> NPNProtocols
110
+ npnProtocolsString = unsafeCoerce
111
+ npnProtocolsBuffer :: Buffer -> NPNProtocols
112
+ npnProtocolsBuffer = unsafeCoerce
113
+ npnProtocolsUint8Array :: Uint8Array -> NPNProtocols
114
+ npnProtocolsUint8Array = unsafeCoerce
115
+ npnProtocolsStringArray :: Array String -> NPNProtocols
116
+ npnProtocolsStringArray = unsafeCoerce
117
+ npnProtocolsBufferArray :: Array Buffer -> NPNProtocols
118
+ npnProtocolsBufferArray = unsafeCoerce
119
+ npnProtocolsUint8ArrayArray :: Array Uint8Array -> NPNProtocols
120
+ npnProtocolsUint8ArrayArray = unsafeCoerce
71
121
72
122
-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener)
73
123
npnProtocols :: Option SSLOptions NPNProtocols
74
- npnProtocols = cmap extract $ opt " NPNProtocols"
75
- where
76
- extract (NPNProtocolsString s) = toForeign s
77
- extract (NPNProtocolsBuffer b) = toForeign b
78
- extract (NPNProtocolsUint8Array u) = toForeign u
79
- extract (NPNProtocolsStringArray sa) = toForeign sa
80
- extract (NPNProtocolsBufferArray ba) = toForeign ba
81
- extract (NPNProtocolsUint8ArrayArray ua) = toForeign ua
124
+ npnProtocols = opt " NPNProtocols"
82
125
83
126
-- | The alpnProtocols option can be a String, a Buffer, a Uint8Array, or an
84
127
-- | array of any of those types.
85
128
data ALPNProtocols
86
- = ALPNProtocolsString String
87
- | ALPNProtocolsBuffer Buffer
88
- | ALPNProtocolsUint8Array Uint8Array
89
- | ALPNProtocolsStringArray (Array String )
90
- | ALPNProtocolsBufferArray (Array Buffer )
91
- | ALPNProtocolsUint8ArrayArray (Array Uint8Array )
129
+ alpnProtocolsString :: String -> ALPNProtocols
130
+ alpnProtocolsString = unsafeCoerce
131
+ alpnProtocolsBuffer :: Buffer -> ALPNProtocols
132
+ alpnProtocolsBuffer = unsafeCoerce
133
+ alpnProtocolsUint8Array :: Uint8Array -> ALPNProtocols
134
+ alpnProtocolsUint8Array = unsafeCoerce
135
+ alpnProtocolsStringArray :: Array String -> ALPNProtocols
136
+ alpnProtocolsStringArray = unsafeCoerce
137
+ alpnProtocolsBufferArray :: Array Buffer -> ALPNProtocols
138
+ alpnProtocolsBufferArray = unsafeCoerce
139
+ alpnProtocolsUint8ArrayArray :: Array Uint8Array -> ALPNProtocols
140
+ alpnProtocolsUint8ArrayArray = unsafeCoerce
92
141
93
142
-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener)
94
143
alpnProtocols :: Option SSLOptions ALPNProtocols
95
- alpnProtocols = cmap extract $ opt " ALPNProtocols"
96
- where
97
- extract (ALPNProtocolsString s) = toForeign s
98
- extract (ALPNProtocolsBuffer b) = toForeign b
99
- extract (ALPNProtocolsUint8Array u) = toForeign u
100
- extract (ALPNProtocolsStringArray sa) = toForeign sa
101
- extract (ALPNProtocolsBufferArray ba) = toForeign ba
102
- extract (ALPNProtocolsUint8ArrayArray ua) = toForeign ua
144
+ alpnProtocols = opt " ALPNProtocols"
103
145
104
146
-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener)
105
147
sessionTimeout :: Option SSLOptions Int
@@ -110,31 +152,31 @@ ticketKeys :: Option SSLOptions Buffer
110
152
ticketKeys = opt " ticketKeys"
111
153
112
154
-- | The PFX option can take either a String or a Buffer
113
- data PFX = PFXString String | PFXBuffer Buffer
155
+ data PFX
156
+ pfxString :: String -> PFX
157
+ pfxString = unsafeCoerce
158
+ pfxBuffer :: Buffer -> PFX
159
+ pfxBuffer = unsafeCoerce
114
160
115
161
-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options)
116
162
pfx :: Option SSLOptions PFX
117
- pfx = cmap extract $ opt " pfx"
118
- where
119
- extract (PFXString s) = toForeign s
120
- extract (PFXBuffer b) = toForeign b
163
+ pfx = opt " pfx"
121
164
122
165
-- | The key option can be a String, a Buffer, an array of strings, or an array
123
166
-- | of buffers.
124
167
data Key
125
- = KeyString String
126
- | KeyBuffer Buffer
127
- | KeyStringArray (Array String )
128
- | KeyBufferArray (Array Buffer )
168
+ keyString :: String -> Key
169
+ keyString = unsafeCoerce
170
+ keyBuffer :: Buffer -> Key
171
+ keyBuffer = unsafeCoerce
172
+ keyStringArray :: Array String -> Key
173
+ keyStringArray = unsafeCoerce
174
+ keyBufferArray :: Array Buffer -> Key
175
+ keyBufferArray = unsafeCoerce
129
176
130
177
-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options)
131
178
key :: Option SSLOptions Key
132
- key = cmap extract $ opt " key"
133
- where
134
- extract (KeyString s) = toForeign s
135
- extract (KeyBuffer b) = toForeign b
136
- extract (KeyStringArray sa) = toForeign sa
137
- extract (KeyBufferArray ba) = toForeign ba
179
+ key = opt " key"
138
180
139
181
-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options)
140
182
passphrase :: Option SSLOptions String
@@ -143,53 +185,50 @@ passphrase = opt "passphrase"
143
185
-- | The cert option can be a String, a Buffer, an array of strings, or an array
144
186
-- | of buffers.
145
187
data Cert
146
- = CertString String
147
- | CertBuffer Buffer
148
- | CertStringArray (Array String )
149
- | CertBufferArray (Array Buffer )
188
+ certString :: String -> Cert
189
+ certString = unsafeCoerce
190
+ certBuffer :: Buffer -> Cert
191
+ certBuffer = unsafeCoerce
192
+ certStringArray :: Array String -> Cert
193
+ certStringArray = unsafeCoerce
194
+ certBufferArray :: Array Buffer -> Cert
195
+ certBufferArray = unsafeCoerce
150
196
151
197
-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options)
152
198
cert :: Option SSLOptions Cert
153
- cert = cmap extract $ opt " cert"
154
- where
155
- extract (CertString s) = toForeign s
156
- extract (CertBuffer b) = toForeign b
157
- extract (CertStringArray sa) = toForeign sa
158
- extract (CertBufferArray ba) = toForeign ba
199
+ cert = opt " cert"
159
200
160
201
-- | The CA option can be a String, a Buffer, an array of strings, or an array
161
202
-- | of buffers.
162
203
data CA
163
- = CAString String
164
- | CABuffer Buffer
165
- | CAStringArray (Array String )
166
- | CABufferArray (Array Buffer )
204
+ caString :: String -> CA
205
+ caString = unsafeCoerce
206
+ caBuffer :: Buffer -> CA
207
+ caBuffer = unsafeCoerce
208
+ caStringArray :: Array String -> CA
209
+ caStringArray = unsafeCoerce
210
+ caBufferArray :: Array Buffer -> CA
211
+ caBufferArray = unsafeCoerce
167
212
168
213
-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options)
169
214
ca :: Option SSLOptions CA
170
- ca = cmap extract $ opt " ca"
171
- where
172
- extract (CAString s) = toForeign s
173
- extract (CABuffer b) = toForeign b
174
- extract (CAStringArray sa) = toForeign sa
175
- extract (CABufferArray ba) = toForeign ba
215
+ ca = opt " ca"
176
216
177
217
-- | The CRL option can be a String, a Buffer, an array of strings, or an array
178
218
-- | of buffers.
179
219
data CRL
180
- = CRLString String
181
- | CRLBuffer Buffer
182
- | CRLStringArray (Array String )
183
- | CRLBufferArray (Array Buffer )
220
+ crlString :: String -> CRL
221
+ crlString = unsafeCoerce
222
+ crlBuffer :: Buffer -> CRL
223
+ crlBuffer = unsafeCoerce
224
+ crlStringArray :: Array String -> CRL
225
+ crlStringArray = unsafeCoerce
226
+ crlBufferArray :: Array Buffer -> CRL
227
+ crlBufferArray = unsafeCoerce
184
228
185
229
-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options)
186
230
crl :: Option SSLOptions CRL
187
- crl = cmap extract $ opt " crl"
188
- where
189
- extract (CRLString s) = toForeign s
190
- extract (CRLBuffer b) = toForeign b
191
- extract (CRLStringArray sa) = toForeign sa
192
- extract (CRLBufferArray ba) = toForeign ba
231
+ crl = opt " crl"
193
232
194
233
-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options)
195
234
ciphers :: Option SSLOptions String
@@ -204,14 +243,15 @@ ecdhCurve :: Option SSLOptions String
204
243
ecdhCurve = opt " ecdhCurve"
205
244
206
245
-- | The DHParam option can take either a String or a Buffer
207
- data DHParam = DHParamString String | DHParamBuffer Buffer
246
+ data DHParam
247
+ dhparamString :: String -> DHParam
248
+ dhparamString = unsafeCoerce
249
+ dhparamBuffer :: Buffer -> DHParam
250
+ dhparamBuffer = unsafeCoerce
208
251
209
252
-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options)
210
253
dhparam :: Option SSLOptions DHParam
211
- dhparam = cmap extract $ opt " dhparam"
212
- where
213
- extract (DHParamString s) = toForeign s
214
- extract (DHParamBuffer b) = toForeign b
254
+ dhparam = opt " dhparam"
215
255
216
256
-- | See the [node docs](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options)
217
257
secureProtocol :: Option SSLOptions String
0 commit comments