Name
SPVM::Net::SSLeay - OpenSSL Binding and SSL data strcuture.
Description
Net::SSLeay class in SPVM is a binding for OpenSSL. This class itself represents SSL data structure.
Warnings:
The tests haven't been written yet. The features may be changed without notice.
Usage
use Net::SSLeay;
use Net::SSLeay::Net::SSLeay::SSL_METHOD;
use Net::SSLeay::Net::SSLeay::SSL_CTX;
my $ssl_method = Net::SSLeay::SSL_METHOD->SSLv23_client_method;
my $ssl_ctx = Net::SSLeay::SSL_CTX->new($ssl_method);
my $ssl = Net::SSLeay->new($ssl_ctx);
Examples
See source codes of IO::Socket::SSL about examples of Net::SSLeay.
Fields
operation_error
has operation_error : ro int;
The place where the return value of SSL_get_error.
Class Methods
new
static method new : Net::SSLeay ($ssl_ctx : Net::SSLeay::SSL_CTX);
Creates a new Net::SSLeay object, creates a SSL object by calling SSL_new function given the Net::SSLeay::SSL_CTX object $ssl_ctx, sets the pointer value of the new Net::SSLeay::SSL_CTX object to the return value of SSL_new function, and returns the new Net::SSLeay::SSL_CTX object.
Exceptions:
If SSL_new failed, an exception is thrown with eval_error_id
set to the basic type ID of Net::SSLeay::Error class.
Instance Methods
set_fd
method set_fd : int ($fd : int);
Sets the file descriptor $fd as the input/output facility for the TLS/SSL (encrypted) side by calling SSL_set_fd function, and returns its return value.
Exceptions:
If SSL_set_fd failed, an exception is thrown with eval_error_id
set to the basic type ID of Net::SSLeay::Error class.
set_tlsext_host_name
method set_tlsext_host_name : int ($name : string);
Sets the server name indication ClientHello extension to contain the value name $name by calling SSL_set_tlsext_host_name function.
Exceptions:
The host name $name must be defined. Otherwise an exception is thrown.
If SSL_set_tlsext_host_name failed, an exception is thrown with eval_error_id
set to the basic type ID of Net::SSLeay::Error class.
connect
method connect : int ();
Initiates the TLS/SSL handshake with a server by calling SSL_connect function, and returns its return value.
Exceptions:
If SSL_connect failed, an exception is thrown with eval_error_id
set to the basic type ID of Net::SSLeay::Error class and with "operation_error" field set to the return vlaue of SSL_get_error function given the return value of SSL_connect function.
accept
method accept : int ();
Waits for a TLS/SSL client to initiate the TLS/SSL handshake by calling SSL_accept function, and returns its return value.
Exceptions:
If SSL_accept failed, an exception is thrown with eval_error_id
set to the basic type ID of Net::SSLeay::Error class and with "operation_error" field set to the return vlaue of SSL_get_error function given the return value of SSL_accept function.
shutdown
method shutdown : int ();
Shuts down an active connection represented by an SSL object by calling SSL_shutdown function, and returns its return value.
Exceptions:
If SSL_shutdown failed, an exception is thrown with eval_error_id
set to the basic type ID of Net::SSLeay::Error class and with "operation_error" field set to the return vlaue of SSL_get_error function given the return value of SSL_shutdown function.
read
method read : int ($buf : mutable string, $num : int = -1, $offset : int = 0);
Try to read $num bytes into the buffer $buf at the offset $offset by calling SSL_read, and returns its return value.
Exceptions:
The buffer $buf must be defined. Otherwise an exception is thrown.
The offset $offset must be greater than or equal to 0. Otherwise an exception is thrown.
The offset $offset + $num must be lower than or equal to the length of the buffer $buf. Otherwise an exception is thrown.
If SSL_read failed, an exception is thrown with eval_error_id
set to the basic type ID of Net::SSLeay::Error class and with "operation_error" field set to the return vlaue of SSL_get_error function given the return value of SSL_read function.
peek
method peek : int ($buf : mutable string, $num : int = -1, $offset : int = 0);
Identical to "read" respectively except no bytes are actually removed from the underlying BIO during the read.
This method calls SSL_peek function.
Exceptions:
The buffer $buf must be defined. Otherwise an exception is thrown.
The offset $offset must be greater than or equal to 0. Otherwise an exception is thrown.
The offset $offset + $num must be lower than or equal to the length of the buffer $buf. Otherwise an exception is thrown.
If SSL_peek failed, an exception is thrown with eval_error_id
set to the basic type ID of Net::SSLeay::Error class and with "operation_error" field set to the return vlaue of SSL_get_error function given the return value of SSL_peek function.
write
method write : int ($buf : string, $num : int = -1, $offset : int = 0);
Writes $num bytes from the buffer $buf at the offset $offset into the specified ssl connection by calling SSL_write function, and returns its return value.
Exceptions:
The buffer $buf must be defined. Otherwise an exception is thrown.
The offset $offset must be greater than or equal to 0. Otherwise an exception is thrown.
The offset $offset + $num must be lower than or equal to the length of the buffer $buf. Otherwise an exception is thrown.
If SSL_write failed, an exception is thrown with eval_error_id
set to the basic type ID of Net::SSLeay::Error class and with "operation_error" field set to the return vlaue of SSL_get_error function given the return value of SSL_write function.
DESTROY
method DESTROY : void ();
Frees SSL object by calling SSL_free function if no_free
flag of the instance is not a true value.
Modules
Config Builder
SPVM::Net::SSLeay::ConfigBuilder
Porting
This class is a Perl's Net::SSLeay porting to SPVM.
Repository
Author
Yuki Kimoto<kimoto.yuki@gmail.com>
Copyright & License
Copyright (c) 2023 Yuki Kimoto
MIT License