File: Cipher.py

package info (click to toggle)
m2crypto 0.21.1-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,416 kB
  • sloc: python: 19,564; makefile: 21; ansic: 18; sh: 17
file content (44 lines) | stat: -rw-r--r-- 1,070 bytes parent folder | download | duplicates (5)
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
"""SSL Ciphers

Copyright (c) 1999-2003 Ng Pheng Siong. All rights reserved."""

__all__ = ['Cipher', 'Cipher_Stack']

from M2Crypto import m2

class Cipher:
    def __init__(self, cipher):
        self.cipher=cipher

    def __len__(self):
        return m2.ssl_cipher_get_bits(self.cipher)

    def __repr__(self):
        return "%s-%s" % (self.name(), len(self))

    def __str__(self):
        return "%s-%s" % (self.name(), len(self))

    def version(self):
        return m2.ssl_cipher_get_version(self.cipher)

    def name(self):
        return m2.ssl_cipher_get_name(self.cipher)


class Cipher_Stack:
    def __init__(self, stack):
        self.stack=stack

    def __len__(self):
        return m2.sk_ssl_cipher_num(self.stack)

    def __getitem__(self, idx):
        if not 0 <= idx < m2.sk_ssl_cipher_num(self.stack):
            raise IndexError('index out of range')
        v=m2.sk_ssl_cipher_value(self.stack, idx)
        return Cipher(v)

    def __iter__(self):
        for i in xrange(m2.sk_ssl_cipher_num(self.stack)):
            yield self[i]