File: protocols.rb

package info (click to toggle)
libopenssl-ruby 0.1.4a-1sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 556 kB
  • ctags: 701
  • sloc: ansic: 6,200; ruby: 1,538; makefile: 45
file content (55 lines) | stat: -rw-r--r-- 1,293 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
=begin

= protocols.rb -- SSL/TLS enhancement for Net.

  Copyright (C) 2001 GOTOU YUUZOU <gotoyuzo@notwork.org>

  This program requires Net 1.2.0 or higher version.
  You can get it from RAA or Ruby's CVS repository.

  $IPR: protocols.rb,v 1.1 2001/06/17 14:30:22 gotoyuzo Exp $

  2001/11/06: Contiributed to Ruby/OpenSSL project.
  $Id: protocols.rb,v 1.2 2001/11/16 15:36:38 gotoyuzo Exp $

=end

require 'net/protocol'
require 'forwardable'
require 'openssl'

module Net
  module NetPrivate

    class SSLSocket < Socket
      extend Forwardable

      def_delegators(:@socket,
                     :key=, :cert=, :key_file=, :cert_file=,
                     :ca_file=, :ca_path=,
                     :verify_mode=, :verify_callback=, :verify_depth=,
                     :timeout=)

      def initialize(addr, port, otime = nil, rtime = nil, pipe = nil)
        super
        @raw_socket = @socket
        @socket = OpenSSL::SSL::SSLSocket.new(@raw_socket)
      end

      def reopen(tout=nil)
        super
        @raw_socket = @socket
        @socket = OpenSSL::SSL::SSLSocket.new(@raw_socket)
      end

      def close
        super
        @raw_socket.close
      end

      def peer_cert; @socket.peer_cert; end
      def ssl_connect; @socket.connect; end

    end
  end
end