Skip to content

Commit

Permalink
added .verify attribute to SuberBase so that subclasses can init to r…
Browse files Browse the repository at this point in the history
…everifiy whan deserializatin

default is False.
  • Loading branch information
SmithSamuelM committed Mar 18, 2024
1 parent a20d33d commit 9b19e15
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/keri/db/subing.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,16 @@ class SuberBase():
db (dbing.LMDBer): base LMDB db
sdb (lmdb._Database): instance of lmdb named sub db for this Suber
sep (str): separator for combining keys tuple of strs into key bytes
verify (bool): some subclasses want to re-verify when deser from db
default false
"""
Sep = '.' # separator for combining key iterables

def __init__(self, db: dbing.LMDBer, *,
subkey: str='docs.',
dupsort: bool=False,
sep: str=None,
verify: bool=False,
**kwa):
"""
Parameters:
Expand All @@ -77,10 +80,12 @@ def __init__(self, db: dbing.LMDBer, *,
sep (str): separator to convert keys iterator to key bytes for db key
default is self.Sep == '.'
"""
super(SuberBase, self).__init__()
super(SuberBase, self).__init__() # for multi inheritance
self.db = db
self.sdb = self.db.env.open_db(key=subkey.encode("utf-8"), dupsort=dupsort)
self.sep = sep if sep is not None else self.Sep
self.verify = True if verify else False



def _tokey(self, keys: Union[str, bytes, memoryview, Iterable],
Expand Down Expand Up @@ -1113,7 +1118,7 @@ def get(self, keys: Union[str, Iterable]):
"""
val = self.db.getVal(db=self.sdb, key=self._tokey(keys))
return self.klas(raw=bytes(val)) if val is not None else None
return self.klas(raw=bytes(val), verify=self.verify) if val is not None else None


def rem(self, keys: Union[str, Iterable]):
Expand Down Expand Up @@ -1145,7 +1150,7 @@ def getItemIter(self, keys: Union[str, Iterable]=b""):
"""
for iokey, val in self.db.getTopItemIter(db=self.sdb, key=self._tokey(keys)):
yield self._tokeys(iokey), self.klas(raw=bytes(val))
yield self._tokeys(iokey), self.klas(raw=bytes(val), verify=self.verify)


class SchemerSuber(Suber):
Expand Down

0 comments on commit 9b19e15

Please sign in to comment.