Reading any ASCII share text from its bytes #
decodePackedForm (in FastDecode) reads well-formed hex shares from their bytes and hands
everything else to the list-based decodeShare: a share that is cut short, has a character that
is not a hex digit, or is written in upper case. For a share of a 1 MiB secret that costs about
100 MB.
decodeAscii reads any text made of ASCII bytes without a list as long as the text. It follows
decodeShare: trim, decide between hex and words, check the length, count the -, cut at them,
decode the fields. Every field is hex-decoded straight from the bytes into a byte array; a field
other than the payload that is too long to be valid is not decoded at all (clip).
decodeAscii_eq proves that it returns exactly what decodeShare returns.
ASCII bytes and characters #
The character with code b. For b < 128 its UTF-8 encoding is the byte b.
Equations
Instances For
Bytes x to y of the array, as characters.
Equations
- QedShare.Cli.seg bs x y = List.map QedShare.Cli.asciiChar (QedShare.Cli.segB bs x y)
Instances For
Loops over a range of bytes #
Hex digits from bytes #
Read n pairs of hex digits from position i into acc; none at a byte that is not a
hex digit.
Equations
- QedShare.Cli.unhexAll bs 0 x✝¹ x✝ = some x✝
- QedShare.Cli.unhexAll bs n.succ x✝¹ x✝ = match QedShare.Cli.hexAt bs x✝¹ with | some b => QedShare.Cli.unhexAll bs n (x✝¹ + 2) (x✝.push b) | none => none
Instances For
Text with an odd number of characters is not hex.
unhexAll is Hex.decode on the bytes it reads, as characters.
Decoding the fields, with the payload as a byte array #
The bytes of a hex field, as a byte array.
Equations
Instances For
decodeFields on fields that are already hex-decoded into byte arrays, giving a packed
record (fieldsPacked_eq). Only the payload stays an array; the other fields are short in any
share, and are looked at as lists like in decodeFields.
Equations
- One or more equations did not get rendered due to their size.
- QedShare.Cli.fieldsPacked f sid kk xx pl✝ tk cc = Except.error QedShare.Encoding.DecodeError.badField
Instances For
decodeChars after the text is cut into its tag t and the other fields, hex-decoded
(tagged_eq).
Equations
- One or more equations did not get rendered due to their size.
- QedShare.Cli.decodeTagged t ds = Except.error QedShare.Encoding.DecodeError.badLayout
Instances For
The list of a byte array made from a list is that list.
fieldsPacked on the hex-decoded fields is decodeFields, packed.
decodeTagged on the tag and the hex-decoded other fields is decodeChars, packed.
Trimming #
trimWs removes the whitespace around text that starts and ends with other characters.
decodeShare only looks at the trimmed text.
Segments of ASCII bytes #
The trimmed text of an ASCII string, as a segment of its bytes: whitespace before i and
from j on, other bytes at i and j − 1.
The fields of a hex share #
How many of the n bytes from position i satisfy p, added to acc.
Equations
- QedShare.Cli.countBytes p bs 0 x✝¹ x✝ = x✝
- QedShare.Cli.countBytes p bs n.succ x✝¹ x✝ = QedShare.Cli.countBytes p bs n (x✝¹ + 1) (if p (bs.get! x✝¹) = true then x✝ + 1 else x✝)
Instances For
countBytes is List.countP on the bytes it reads.
countBytes on a segment.
Text has one field more than it has -.
Text that does not have 6 or 7 fields is not a share.
Check that the positions ps are the - between i and j, and give the fields they cut
that range into, as ranges.
Equations
Instances For
The positions of the bytes 45 between i and j. Nothing is proven about it: cutAt
checks them.
Equations
- QedShare.Cli.dashes bs i j = QedShare.Cli.dashesLoop bs (j - i) i #[]
Instances For
The reader #
Texts up to this many bytes are read by the list-based reader: lists that short cost nothing worth saving.
Equations
- QedShare.Cli.smallText = 16384
Instances For
A hex field that is too long for any field but the payload reads as "not hex": every such
field has at most 16 bytes, so the result is the same (fieldsPacked_clip_sid and the
following), and no list of a long field is ever built.
Instances For
More than four bytes are not a 32-bit number.
fieldsPacked gives the same for a set-id field that is too long as for one that is not
hex.
fieldsPacked gives the same for a set-id field that is too long as for one that is not
hex.
fieldsPacked gives the same for a set-id field that is too long as for one that is not
hex.
fieldsPacked gives the same for a set-id field that is too long as for one that is not
hex.
fieldsPacked gives the same for a set-id field that is too long as for one that is not
hex.
The payload field r, hex-decoded from the bytes.
Equations
Instances For
The fields after the tag, hex-decoded from the bytes: the payload in full, the others only if they are short.
Equations
- One or more equations did not get rendered due to their size.
- QedShare.Cli.fieldsOf bs [a, b, c, d, e] = [QedShare.Cli.shortR bs a, QedShare.Cli.shortR bs b, QedShare.Cli.shortR bs c, QedShare.Cli.unhexR bs d, QedShare.Cli.shortR bs e]
- QedShare.Cli.fieldsOf bs x✝ = []
Instances For
A tag has three characters.
decodeTagged only looks at the format the tag names.
Read one share from ASCII bytes without a list as long as the text; none if the bytes are
not all ASCII (then the caller uses decodeShare). What it returns is what looksHex and
decodeShare return (decodeAscii_eq).
It follows decodeShare: trim (the ends found by skipWs and skipWsEnd are checked), decide
between hex and words, check the length, count the - (anything but 5 or 6 is not a share), cut
at them (the positions found by dashes are checked by cutAt), and decode the fields from the
bytes.
Equations
- One or more equations did not get rendered due to their size.
Instances For
decodeAscii reads what decodeShare reads. Whenever it gives an answer for the bytes
of a text, that answer is whether the text is in the hex form (looksHex), and the packed
record decodeShare returns, or the same error.