# Path: axolotl/groups/state/senderkeystore.py
# class SenderKeyStore(object):
#     __metaclass__ = abc.ABCMeta
# 
#     @abc.abstractmethod
#     def storeSenderKey(self, senderKeyId, senderKeyRecord):
#         """
#         :type senderKeyId: str
#         :type senderKeyRecord: SenderKeyRecord
#         """
# 
#     @abc.abstractmethod
#     def loadSenderKey(self, senderKeyId):
#         """
#         :type senderKeyId: str
#         """
# 
# Path: axolotl/groups/state/senderkeyrecord.py
# class SenderKeyRecord:
#     def __init__(self, serialized=None):
#         self.senderKeyStates = []
# 
#         if serialized:
#             senderKeyRecordStructure = SenderKeyRecordStructure()
#             senderKeyRecordStructure.ParseFromString(serialized)
# 
#             for structure in senderKeyRecordStructure.senderKeyStates:
#                 self.senderKeyStates.append(SenderKeyState(senderKeyStateStructure=structure))
# 
# 
#     def isEmpty(self):
#         return len(self.senderKeyStates) == 0
# 
#     def getSenderKeyState(self, keyId=None):
#         if keyId is None:
#             if len(self.senderKeyStates):
#                 return self.senderKeyStates[0]
#             else:
#                 raise InvalidKeyIdException("No key state in record")
#         else:
#             for state in self.senderKeyStates:
#                 if state.getKeyId() == keyId:
#                     return state
#             raise InvalidKeyIdException("No keys for: %s" % keyId)
# 
#     def addSenderKeyState(self, id, iteration, chainKey, signatureKey):
#         """
#         :type id: int
#         :type iteration: int
#         :type chainKey: bytearray
#         :type signatureKey: ECPublicKey
#         """
#         self.senderKeyStates.append(SenderKeyState(id, iteration, chainKey, signatureKey))
# 
#     def setSenderKeyState(self, id, iteration, chainKey, signatureKey):
#         """
#         :type id: int
#         :type iteration: int
#         :type chainKey: bytearray
#         :type signatureKey: ECKeyPair
#         """
#         del self.senderKeyStates[:]
#         self.senderKeyStates.append(SenderKeyState(id, iteration, chainKey, signatureKeyPair=signatureKey))
# 
#     def serialize(self):
#         recordStructure = SenderKeyRecordStructure()
# 
#         for senderKeyState in self.senderKeyStates:
#             recordStructure.senderKeyStates.extend([senderKeyState.getStructure()])
# 
#         return recordStructure.SerializeToString()


from ...groups.state.senderkeystore import SenderKeyStore
from ...groups.state.senderkeyrecord import SenderKeyRecord
# -*- coding: utf-8 -*-



class InMemorySenderKeyStore(SenderKeyStore):
    def __init__(self):
        self.store = {}

    def storeSenderKey(self, senderKeyName, senderKeyRecord):
        self.store[senderKeyName] = senderKeyRecord

    def loadSenderKey(self, senderKeyName):
        if senderKeyName in self.store:
            return SenderKeyRecord(serialized=self.store[senderKeyName].serialize())


# Path: axolotl/groups/state/senderkeystore.py
# class SenderKeyStore(object):
#     __metaclass__ = abc.ABCMeta
# 
#     @abc.abstractmethod
#     def storeSenderKey(self, senderKeyId, senderKeyRecord):
#         """
#         :type senderKeyId: str
#         :type senderKeyRecord: SenderKeyRecord
#         """
# 
#     @abc.abstractmethod
#     def loadSenderKey(self, senderKeyId):
#         """
#         :type senderKeyId: str
#         """
# 
# Path: axolotl/groups/state/senderkeyrecord.py
# class SenderKeyRecord:
#     def __init__(self, serialized=None):
#         self.senderKeyStates = []
# 
#         if serialized:
#             senderKeyRecordStructure = SenderKeyRecordStructure()
#             senderKeyRecordStructure.ParseFromString(serialized)
# 
#             for structure in senderKeyRecordStructure.senderKeyStates:
#                 self.senderKeyStates.append(SenderKeyState(senderKeyStateStructure=structure))
# 
# 
#     def isEmpty(self):
#         return len(self.senderKeyStates) == 0
# 
#     def getSenderKeyState(self, keyId=None):
#         if keyId is None:
#             if len(self.senderKeyStates):
#                 return self.senderKeyStates[0]
#             else:
#                 raise InvalidKeyIdException("No key state in record")
#         else:
#             for state in self.senderKeyStates:
#                 if state.getKeyId() == keyId:
#                     return state
#             raise InvalidKeyIdException("No keys for: %s" % keyId)
# 
#     def addSenderKeyState(self, id, iteration, chainKey, signatureKey):
#         """
#         :type id: int
#         :type iteration: int
#         :type chainKey: bytearray
#         :type signatureKey: ECPublicKey
#         """
#         self.senderKeyStates.append(SenderKeyState(id, iteration, chainKey, signatureKey))
# 
#     def setSenderKeyState(self, id, iteration, chainKey, signatureKey):
#         """
#         :type id: int
#         :type iteration: int
#         :type chainKey: bytearray
#         :type signatureKey: ECKeyPair
#         """
#         del self.senderKeyStates[:]
#         self.senderKeyStates.append(SenderKeyState(id, iteration, chainKey, signatureKeyPair=signatureKey))
# 
#     def serialize(self):
#         recordStructure = SenderKeyRecordStructure()
# 
#         for senderKeyState in self.senderKeyStates:
#             recordStructure.senderKeyStates.extend([senderKeyState.getStructure()])
# 
#         return recordStructure.SerializeToString()


# Path: axolotl/tests/groups/inmemorysenderkeystore.py
from ...groups.state.senderkeystore import SenderKeyStore
from ...groups.state.senderkeyrecord import SenderKeyRecord

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



class InMemorySenderKeyStore(SenderKeyStore):
    def __init__(self):
        self.store = {}

    def storeSenderKey(self, senderKeyName, senderKeyRecord):
        self.store[senderKeyName] = senderKeyRecord

    def loadSenderKey(self, senderKeyName):
        if senderKeyName in self.store:
            return SenderKeyRecord(serialized=self.store[senderKeyName].serialize())


        return SenderKeyRecord()