File: dual.py

package info (click to toggle)
python-libnacl 2.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 488 kB
  • sloc: python: 2,634; makefile: 149; sh: 3
file content (35 lines) | stat: -rw-r--r-- 889 bytes parent folder | download | duplicates (2)
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
'''
The dual key system allows for the creation of keypairs that contain both
cryptographic and signing keys
'''
# import libnacl libs
import libnacl
import libnacl.base
import libnacl.public
import libnacl.sign


class DualSecret(libnacl.base.BaseKey):
    '''
    Manage crypt and sign keys in one object
    '''
    def __init__(self, crypt=None, sign=None):
        self.crypt = libnacl.public.SecretKey(crypt)
        self.signer = libnacl.sign.Signer(sign)
        self.sk = self.crypt.sk
        self.seed = self.signer.seed
        self.pk = self.crypt.pk
        self.vk = self.signer.vk
        super().__init__()

    def sign(self, msg):
        '''
        Sign the given message
        '''
        return self.signer.sign(msg)

    def signature(self, msg):
        '''
        Return just the signature for the message
        '''
        return self.signer.signature(msg)