# Path: axolotl/state/prekeystore.py
# class PreKeyStore(object):
#     __metaclass__ = abc.ABCMeta
# 
#     @abc.abstractmethod
#     def loadPreKey(self, preKeyId):
#         pass
# 
#     @abc.abstractmethod
#     def storePreKey(self, preKeyId, preKeyRecord):
#         pass
# 
#     @abc.abstractmethod
#     def containsPreKey(self, preKeyId):
#         pass
# 
#     @abc.abstractmethod
#     def removePreKey(self, preKeyId):
#         pass
# 
# Path: axolotl/state/prekeyrecord.py
# class PreKeyRecord:
#     def __init__(self, _id=None, ecKeyPair=None, serialized=None):
#         self.structure = PreKeyRecordStructure()
#         if serialized:
#             self.structure.ParseFromString(serialized)
#         else:
#             self.structure.id = _id
#             self.structure.publicKey = ecKeyPair.getPublicKey().serialize()
#             self.structure.privateKey = ecKeyPair.getPrivateKey().serialize()
# 
#     def getId(self):
#         return self.structure.id
# 
#     def getKeyPair(self):
#         publicKey = Curve.decodePoint(bytearray(self.structure.publicKey), 0)
#         privateKey = Curve.decodePrivatePoint(bytearray(self.structure.privateKey))
#         return ECKeyPair(publicKey, privateKey)
# 
#     def serialize(self):
#         return self.structure.SerializeToString()
# 
# Path: axolotl/invalidkeyidexception.py
# class InvalidKeyIdException(Exception):
#     pass


from ..state.prekeystore import PreKeyStore
from ..state.prekeyrecord import PreKeyRecord
from ..invalidkeyidexception import InvalidKeyIdException
# -*- coding: utf-8 -*-



class InMemoryPreKeyStore(PreKeyStore):
    def __init__(self):
        self.store = {}

    def loadPreKey(self, preKeyId):
        if preKeyId not in self.store:
            raise InvalidKeyIdException("No such prekeyRecord!")

        return PreKeyRecord(serialized=self.store[preKeyId])

    def storePreKey(self, preKeyId, preKeyRecord):

# Path: axolotl/state/prekeystore.py
# class PreKeyStore(object):
#     __metaclass__ = abc.ABCMeta
# 
#     @abc.abstractmethod
#     def loadPreKey(self, preKeyId):
#         pass
# 
#     @abc.abstractmethod
#     def storePreKey(self, preKeyId, preKeyRecord):
#         pass
# 
#     @abc.abstractmethod
#     def containsPreKey(self, preKeyId):
#         pass
# 
#     @abc.abstractmethod
#     def removePreKey(self, preKeyId):
#         pass
# 
# Path: axolotl/state/prekeyrecord.py
# class PreKeyRecord:
#     def __init__(self, _id=None, ecKeyPair=None, serialized=None):
#         self.structure = PreKeyRecordStructure()
#         if serialized:
#             self.structure.ParseFromString(serialized)
#         else:
#             self.structure.id = _id
#             self.structure.publicKey = ecKeyPair.getPublicKey().serialize()
#             self.structure.privateKey = ecKeyPair.getPrivateKey().serialize()
# 
#     def getId(self):
#         return self.structure.id
# 
#     def getKeyPair(self):
#         publicKey = Curve.decodePoint(bytearray(self.structure.publicKey), 0)
#         privateKey = Curve.decodePrivatePoint(bytearray(self.structure.privateKey))
#         return ECKeyPair(publicKey, privateKey)
# 
#     def serialize(self):
#         return self.structure.SerializeToString()
# 
# Path: axolotl/invalidkeyidexception.py
# class InvalidKeyIdException(Exception):
#     pass


# Path: axolotl/tests/inmemoryprekeystore.py
from ..state.prekeystore import PreKeyStore
from ..state.prekeyrecord import PreKeyRecord
from ..invalidkeyidexception import InvalidKeyIdException

# -*- coding: utf-8 -*-



class InMemoryPreKeyStore(PreKeyStore):
    def __init__(self):
        self.store = {}

    def loadPreKey(self, preKeyId):
        if preKeyId not in self.store:
            raise InvalidKeyIdException("No such prekeyRecord!")

        return PreKeyRecord(serialized=self.store[preKeyId])

    def storePreKey(self, preKeyId, preKeyRecord):

        self.store[preKeyId] = preKeyRecord.serialize()