From 2918f86cb465f7f4d3d08252dce69c758bccd273 Mon Sep 17 00:00:00 2001 From: Samuel M Smith Date: Sat, 3 Aug 2024 13:07:52 -0600 Subject: [PATCH] fix doc strings comments --- src/keri/app/habbing.py | 6 +++--- src/keri/app/keeping.py | 7 +++--- src/keri/core/streaming.py | 44 ++++++++++++++++++++++++++++++++------ 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/keri/app/habbing.py b/src/keri/app/habbing.py index 44516caa8..d32a858f5 100644 --- a/src/keri/app/habbing.py +++ b/src/keri/app/habbing.py @@ -1321,13 +1321,13 @@ def sign(self, ser, verfers=None, indexed=True, indices=None, ondices=None, **kw ondices=ondices) def decrypt(self, ser, verfers=None, **kwa): - """Sign given serialization ser using appropriate keys. + """Decrypt given serialization ser using appropriate keys. Use provided verfers or .kever.verfers to lookup keys to sign. Parameters: - ser (bytes): serialization to sign + ser (bytes): serialization to decrypt verfers (list[Verfer] | None): Verfer instances to get pub verifier - keys to lookup private siging keys. + keys to lookup and convert to private decryption keys. verfers None means use .kever.verfers. Assumes that when group and verfers is not None then provided verfers must be .kever.verfers diff --git a/src/keri/app/keeping.py b/src/keri/app/keeping.py index 3a626a622..0e29fff6f 100644 --- a/src/keri/app/keeping.py +++ b/src/keri/app/keeping.py @@ -1394,10 +1394,10 @@ def sign(self, ser, pubs=None, verfers=None, indexed=True, cigars.append(signer.sign(ser)) # assigns .verfer to cigar return cigars + def decrypt(self, ser, pubs=None, verfers=None): """ - Returns list of signatures of ser if indexed as Sigers else as Cigars with - .verfer assigned. + Returns plain text of decrypted serialization Parameters: ser (bytes): serialization to sign @@ -1405,7 +1405,8 @@ def decrypt(self, ser, pubs=None, verfers=None): one of pubs or verfers is required. If both then verfers is ignored. verfers (list[Verfer] | None): Verfer instances of public keys one of pubs or verfers is required. If both then verfers is ignored. - If not pubs then gets public key from verfer.qb64 + If not pubs then gets public key from verfer.qb64 used to lookup + private keys Returns: bytes: decrypted data diff --git a/src/keri/core/streaming.py b/src/keri/core/streaming.py index 617a74d21..4ad253ecc 100644 --- a/src/keri/core/streaming.py +++ b/src/keri/core/streaming.py @@ -48,7 +48,7 @@ def annot(ims): if not isinstance(ims, bytearray): # going to strip - ims = bytearray(ims) # so make bytearray copy + ims = bytearray(ims) # so make bytearray copy, converts str to bytearray while ims: # right now just for KERI event messages cold = sniff(ims) # check for spurious counters at front of stream @@ -342,14 +342,22 @@ class Streamer: def __init__(self, stream): """Initialize instance + Holds sniffable CESR stream as byte like string + either (bytes, bytearray, or memoryview) Parameters: - stream (bytes | bytearray): sniffable CESR stream + stream (str | bytes | bytearray | memoryview): sniffable CESR stream + """ - self._stream = bytes(stream) + if hasattr(stream, "encode"): + stream = bytearray(stream.encode()) # convert str to bytearray + if not isinstance(stream, (bytes, bytearray, memoryview)): + raise kering.InvalidTypeError(f"Invalid stream type, not byteable.") + + self._stream = stream @property @@ -360,7 +368,9 @@ def stream(self): @property def text(self): - """expanded stream as qb64 text + """expanded stream where all primitives and groups in stream are + individually expanded to qb64. + Requires parsing full depth to ensure expanded consistently. Returns: stream (bytes): expanded text qb64 version of stream @@ -369,7 +379,9 @@ def text(self): @property def binary(self): - """compacted stream as qb2 binary + """compacted stream where all primitives and groups in stream are + individually compacted to qb2. + Requires parsing full depth to ensure compacted consistently Returns: stream (bytes): compacted binary qb2 version of stream @@ -378,13 +390,33 @@ def binary(self): @property def texter(self): - """expanded stream as Texter instance + """stream as Texter instance. + Texter(text=self.stream) Returns: texter (Texter): Texter primitive of stream suitable wrapping """ return self._stream + @property + def bexter(self): + """stream as Bexter instance. + Bexter of expanded text version of stream. + First expand to text which requires parsing then create bexter + Bexter(bext=self.text) + Because sniffable stream MUST NOT start with 'A' then there is no + length ambiguity. The only tritet collison of 'A' is with '-' but the + remaining 5 bits are guaranteed to always be different. So bexter must + check not just the starting tritet but the full starting byte to ensure + not 'A' as first byte. + + Requires parsing to ensure qb64 + Returns: + bexter (Bexter): Bexter primitive of stream suitable wrapping + + """ + return self._stream +