File: identitykeypair.py

package info (click to toggle)
python-axolotl 0.2.3-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 592 kB
  • sloc: python: 2,962; makefile: 3
file content (29 lines) | stat: -rw-r--r-- 1,021 bytes parent folder | download | duplicates (3)
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
# -*- coding: utf-8 -*-

from .state.storageprotos_pb2 import IdentityKeyPairStructure
from .identitykey import IdentityKey
from .ecc.curve import Curve


class IdentityKeyPair:
    def __init__(self, identityKeyPublicKey=None, ecPrivateKey=None, serialized=None):
        if serialized:
            structure = IdentityKeyPairStructure()
            structure.ParseFromString(serialized)
            self.publicKey = IdentityKey(bytearray(structure.publicKey), offset=0)
            self.privateKey = Curve.decodePrivatePoint(bytearray(structure.privateKey))
        else:
            self.publicKey = identityKeyPublicKey
            self.privateKey = ecPrivateKey

    def getPublicKey(self):
        return self.publicKey

    def getPrivateKey(self):
        return self.privateKey

    def serialize(self):
        structure = IdentityKeyPairStructure()
        structure.publicKey = self.publicKey.serialize()
        structure.privateKey = self.privateKey.serialize()
        return structure.SerializeToString()