# Path: simplekv/decorator.py
# class StoreDecorator(object):
#     """Base class for store decorators.
# 
#     The default implementation will use :func:`getattr` to pass through all
#     attribute/method requests to an underlying object stored as
#     :attr:`_dstore`. It will also pass through the :attr:`__getattr__` and
#     :attr:`__contains__` python special methods.
#     """
# 
#     def __init__(self, store):
#         self._dstore = store
# 
#     def __getattr__(self, attr):
#         store = object.__getattribute__(self, "_dstore")
#         return getattr(store, attr)
# 
#     def __contains__(self, *args, **kwargs):
#         return self._dstore.__contains__(*args, **kwargs)
# 
#     def __iter__(self, *args, **kwargs):
#         return self._dstore.__iter__(*args, **kwargs)


import hashlib
import hmac
import os
import tempfile
from .decorator import StoreDecorator
#!/usr/bin/env python
# coding=utf8




class _HMACFileReader(object):
    def __init__(self, hm, source):
        self.hm = hm
        self.source = source

        # "preload" buffer
        self.buffer = source.read(self.hm.digest_size)
        if not len(self.buffer) == self.hm.digest_size:
            raise VerificationException('Source does not contain HMAC hash '
                                        '(too small)')

    def read(self, n=None):
        if b'' == self.buffer or 0 == n:
            return b''

        new_read = self.source.read(n) if n is not None else self.source.read()
        finished = (n is None or len(new_read) != n)
        self.buffer += new_read

        if n is not None:
            offset = min(n, len(self.buffer) - self.hm.digest_size)
        else:
            offset = len(self.buffer) - self.hm.digest_size


# Path: simplekv/decorator.py
# class StoreDecorator(object):
#     """Base class for store decorators.
# 
#     The default implementation will use :func:`getattr` to pass through all
#     attribute/method requests to an underlying object stored as
#     :attr:`_dstore`. It will also pass through the :attr:`__getattr__` and
#     :attr:`__contains__` python special methods.
#     """
# 
#     def __init__(self, store):
#         self._dstore = store
# 
#     def __getattr__(self, attr):
#         store = object.__getattribute__(self, "_dstore")
#         return getattr(store, attr)
# 
#     def __contains__(self, *args, **kwargs):
#         return self._dstore.__contains__(*args, **kwargs)
# 
#     def __iter__(self, *args, **kwargs):
#         return self._dstore.__iter__(*args, **kwargs)


# Path: simplekv/crypt.py
import hashlib
import hmac
import os
import tempfile
from .decorator import StoreDecorator

#!/usr/bin/env python
# coding=utf8




class _HMACFileReader(object):
    def __init__(self, hm, source):
        self.hm = hm
        self.source = source

        # "preload" buffer
        self.buffer = source.read(self.hm.digest_size)
        if not len(self.buffer) == self.hm.digest_size:
            raise VerificationException('Source does not contain HMAC hash '
                                        '(too small)')

    def read(self, n=None):
        if b'' == self.buffer or 0 == n:
            return b''

        new_read = self.source.read(n) if n is not None else self.source.read()
        finished = (n is None or len(new_read) != n)
        self.buffer += new_read

        if n is not None:
            offset = min(n, len(self.buffer) - self.hm.digest_size)
        else:
            offset = len(self.buffer) - self.hm.digest_size


        rv, self.buffer = self.buffer[:offset], self.buffer[offset:]