Documentation

QedShareCli.Main

Command-line entry point #

The IO shell: read the secret or the shares, fetch OS randomness for split, and write output. All the logic lives in the pure QedShareCli.Pipeline and the verified core.

Usage text printed by qedshare --help.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    def readUpTo (stream : IO.FS.Stream) (limit : Nat) :

    Read stream to its end, or until more than limit bytes were read. In that case the result is longer than limit and the rest is left unread, so an oversized input is refused without first being loaded into memory.

    Equations
    Instances For
      partial def readUpTo.loop (stream : IO.FS.Stream) (limit : Nat) (acc : ByteArray) :
      partial def streamLinesLoop (stream : IO.FS.Stream) (onLine : Nat → ByteArray → IO Unit) (st : QedShare.Cli.LineCut) (reserved : Bool) :

      Loop for streamLines. reserved says that the bytes kept for the current line already have room for a whole share.

      def streamLines (stream : IO.FS.Stream) (onLine : Nat → ByteArray → IO Unit) :

      Read the stream to its end and call onLine with each line (its number, counting from 1, and its bytes without the line feed), one at a time: the stream is never held as a whole.

      Equations
      Instances For
        def withFile {α : Type} (what path : String) (act : IO α) :
        IO α

        Run act; if it fails, say which file it was working on. (Some OS errors, such as "is a directory", do not name the file.)

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For

          Read the secret from the file, or from stdin, refusing one over maxSecretBytes before reading the rest of it.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            def writePrivate (path : System.FilePath) (content : ByteArray) :

            Create the new file path for its owner only and write content to it.

            writeNew fails if path already exists, so nothing is ever overwritten, even if the file appears between an earlier check and this call. The access rights are narrowed while the file is still empty, before any content is written. If writing fails, the unfinished file is removed.

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For

              Fail if path exists: split and combine never overwrite a file.

              Equations
              Instances For
                def runSplit (k n : Nat) (input outDir : Option String) (form : QedShare.Cli.ShareForm) :

                Run split.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  def forShares (files : List String) (emit : String → (bs : ByteArray) → bs.IsValidUTF8 → IO Unit) :

                  Go through the shares in the files (one share each, or one per line), or one per non-blank line of stdin, and call emit with each of them (its label and the UTF-8 bytes of its text), in the order and with the labels of stdinShares and fileShares.

                  The input is never held as a whole where that can be avoided: each file is read before the next one is opened, and stdin is read one line at a time. A regular file is looked at line by line first, and then read line by line too if that pass shows how fileShareRanges would cut it:

                  • no line that is not blank: the file reads like empty text;
                  • one such line: that line is the file's share;
                  • several, all looking like hex shares: each line is a share;
                  • several, not all looking like hex shares, and more text than a word share can have: the file as a whole is not a share (it is not hex text, because it has a line feed inside, and it is too long for words). So each line is a share if at least one of them reads as a share, and otherwise the file is one share, which is read as a whole to say what is wrong with it.

                  Any other file (a word share wrapped over several lines, or something that is not a regular file) is read as a whole and cut by fileShareRanges.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    def readSharesWith {α : Type} (files : List String) (read : String → (bs : ByteArray) → bs.IsValidUTF8 → α) :
                    IO (List (String × α))

                    Read the shares (see forShares) and read each of them with read. Only what read returns is kept, not the text.

                    The result is read applied to every labelled share, in the order and with the labels of stdinShares and fileShares: what the …Bytes functions of FastCombine and FastInfo take apart the same way.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For
                      def runCombine (files : List String) (out : Option String) :

                      Run combine.

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For

                        Whether every path is a regular file, which can be read a second time.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For

                          Run convert. Nothing is printed unless every share can be converted.

                          Shares in regular files are read twice: once to check that every one converts, and once more to print each converted share as soon as it is made, so that no output is held. (If a file changes between the two, the second pass stops with the error, after the shares before it.) Shares on stdin, or in something that can be read only once, are kept as packed records until the last one is read, and then printed one by one.

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For
                            def runVerify (files : List String) :

                            Run verify.

                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For
                              def runInfo (files : List String) :

                              Run info. Every share is described, also when some cannot be read; that case is still an error (exit code 1).

                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For
                                def main (args : List String) :

                                Entry point of the qedshare command-line tool. Returns the process exit code: 0 success, 1 runtime error, 2 bad usage.

                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For