diff options
Diffstat (limited to 'lib/pure/sockets.nim')
-rw-r--r-- | lib/pure/sockets.nim | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/lib/pure/sockets.nim b/lib/pure/sockets.nim index 36389edcc..99cdc002c 100644 --- a/lib/pure/sockets.nim +++ b/lib/pure/sockets.nim @@ -55,7 +55,7 @@ when defined(ssl): SSLProtVersion* = enum protSSLv2, protSSLv3, protTLSv1, protSSLv23 - SSLContext* = distinct PSSLCTX + SSLContext* = distinct SSLCTX SSLAcceptResult* = enum AcceptNoClient = 0, AcceptNoHandshake, AcceptSuccess @@ -79,7 +79,7 @@ type when defined(ssl): case isSsl: bool of true: - sslHandle: PSSL + sslHandle: SSLPtr sslContext: SSLContext sslNoHandshake: bool # True if needs handshake. sslHasPeekChar: bool @@ -254,21 +254,21 @@ when defined(ssl): proc raiseSSLError(s = "") = if s != "": - raise newException(ESSL, s) + raise newException(SSLError, s) let err = ErrPeekLastError() if err == 0: - raise newException(ESSL, "No error reported.") + raise newException(SSLError, "No error reported.") if err == -1: raiseOSError(osLastError()) var errStr = ErrErrorString(err, nil) - raise newException(ESSL, $errStr) + raise newException(SSLError, $errStr) # http://simplestcodings.blogspot.co.uk/2010/08/secure-server-client-using-openssl-in-c.html - proc loadCertificates(ctx: PSSL_CTX, certFile, keyFile: string) = + proc loadCertificates(ctx: SSL_CTX, certFile, keyFile: string) = if certFile != "" and not existsFile(certFile): - raise newException(system.EIO, "Certificate file could not be found: " & certFile) + raise newException(system.IOError, "Certificate file could not be found: " & certFile) if keyFile != "" and not existsFile(keyFile): - raise newException(system.EIO, "Key file could not be found: " & keyFile) + raise newException(system.IOError, "Key file could not be found: " & keyFile) if certFile != "": var ret = SSLCTXUseCertificateChainFile(ctx, certFile) @@ -285,7 +285,7 @@ when defined(ssl): raiseSslError("Verification of private key file failed.") proc newContext*(protVersion = protSSLv23, verifyMode = CVerifyPeer, - certFile = "", keyFile = ""): PSSLContext = + certFile = "", keyFile = ""): SSLContext = ## Creates an SSL context. ## ## Protocol version specifies the protocol to use. SSLv2, SSLv3, TLSv1 are @@ -301,7 +301,7 @@ when defined(ssl): ## path, a server socket will most likely not work without these. ## Certificates can be generated using the following command: ## ``openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem``. - var newCTX: PSSL_CTX + var newCTX: SSL_CTX case protVersion of protSSLv23: newCTX = SSL_CTX_new(SSLv23_method()) # SSlv2,3 and TLS1 support. @@ -327,9 +327,9 @@ when defined(ssl): discard newCTX.SSLCTXSetMode(SSL_MODE_AUTO_RETRY) newCTX.loadCertificates(certFile, keyFile) - return PSSLContext(newCTX) + return SSLContext(newCTX) - proc wrapSocket*(ctx: PSSLContext, socket: TSocket) = + proc wrapSocket*(ctx: SSLContext, socket: Socket) = ## Wraps a socket in an SSL context. This function effectively turns ## ``socket`` into an SSL socket. ## @@ -338,7 +338,7 @@ when defined(ssl): socket.isSSL = true socket.sslContext = ctx - socket.sslHandle = SSLNew(PSSLCTX(socket.sslContext)) + socket.sslHandle = SSLNew(SSLCTX(socket.sslContext)) socket.sslNoHandshake = false socket.sslHasPeekChar = false if socket.sslHandle == nil: @@ -561,9 +561,9 @@ proc setBlocking*(s: Socket, blocking: bool) {.tags: [], gcsafe.} ## Sets blocking mode on socket when defined(ssl): - proc acceptAddrSSL*(server: TSocket, client: var TSocket, - address: var string): TSSLAcceptResult {. - tags: [FReadIO].} = + proc acceptAddrSSL*(server: Socket, client: var Socket, + address: var string): SSLAcceptResult {. + tags: [ReadIOEffect].} = ## This procedure should only be used for non-blocking **SSL** sockets. ## It will immediately return with one of the following values: ## @@ -886,7 +886,7 @@ proc connectAsync*(socket: Socket, name: string, port = Port(0), socket.sslNoHandshake = true when defined(ssl): - proc handshake*(socket: TSocket): bool {.tags: [FReadIO, FWriteIO].} = + proc handshake*(socket: Socket): bool {.tags: [ReadIOEffect, WriteIOEffect].} = ## This proc needs to be called on a socket after it connects. This is ## only applicable when using ``connectAsync``. ## This proc performs the SSL handshake. @@ -916,7 +916,7 @@ when defined(ssl): else: raiseSslError("Socket is not an SSL socket.") - proc gotHandshake*(socket: TSocket): bool = + proc gotHandshake*(socket: Socket): bool = ## Determines whether a handshake has occurred between a client (``socket``) ## and the server that ``socket`` is connected to. ## @@ -1689,7 +1689,7 @@ proc setBlocking(s: Socket, blocking: bool) = raiseOSError(osLastError()) s.nonblocking = not blocking -discard """ proc setReuseAddr*(s: TSocket) = +discard """ proc setReuseAddr*(s: Socket) = var blah: int = 1 var mode = SO_REUSEADDR if setsockopt(s.fd, SOL_SOCKET, mode, addr blah, TSOcklen(sizeof(int))) == -1: |