All files

src/stdlib/digest/sha256/errors.panack

Green: covered; red: known zero; amber: unavailable. Blank lines are outside the executable-start-line denominator.

    1 pub import stdlib/host::{HostError}
    2 pub enum Sha256Operation { Create, Update(Nat), Finish, Close }
    3 pub enum Sha256ErrorKind {
    4   InvalidContext, ChunkTooLarge, InvalidArgument, InitializationFailed,
    5   DigestFailed, ResourceLimit, UnsupportedHost, OtherFailure
    6 }
    7 pub record Sha256Error { operation: Sha256Operation, kind: Sha256ErrorKind, native: HostError }
    8 
    9 impl Sha256Error {
   10   pub pure render(): Str {
   11     action = match self.operation {
   12       Create() => "create a SHA-256 context",
   13       Update(size) => "update a SHA-256 context with ${size} bytes",
   14       Finish() => "finish a SHA-256 digest",
   15       Close() => "close a SHA-256 context"
   16     }
   17     reason = match self.kind {
   18       InvalidContext() => "the context is not usable in this invocation. Use a context created here that has not been finished, closed or invalidated by a digest failure",
   19       ChunkTooLarge() => "an update accepts at most 65536 bytes. Split the input into smaller chunks and update the context with each chunk",
   20       InvalidArgument() => "the host rejected an argument. Check the operation’s documented requirements",
   21       InitializationFailed() => "OpenSSL could not initialise a SHA-256 context. No context was created; the native API has not supplied a more specific cause",
   22       DigestFailed() => "OpenSSL could not complete the digest operation. The context is no longer usable; create a new context and supply the input again",
   23       ResourceLimit() => "the host could not allocate another context slot. An invocation can create at most 65536 contexts, including contexts already finished or closed; closing a context does not reset that quota",
   24       UnsupportedHost() => "this host does not support SHA-256 contexts",
   25       OtherFailure() => "the host returned an unrecognised failure. The native field preserves its details"
   26     }
   27     number = self.native.native_code
   28     detail = if number == 0 { "" } else { " Host error number: ${number}." }
   29     "Cannot ${action}: ${reason}.${detail}"
   30   }
   31 }
   32 
   33 pub pure convert[T](result: Result[T,HostError], operation: Sha256Operation): Result[T,Sha256Error] {
   34   match result {
   35     Ok(value) => Ok(value),
   36     Error(problem) => {
   37       kind = if problem.code == "invalid_handle" { InvalidContext() }
   38       else if problem.code == "invalid_argument" {
   39         match operation {
   40           Update(size) => if size > 65536 { ChunkTooLarge() } else { InvalidArgument() },
   41           Create() => InvalidArgument(), Finish() => InvalidArgument(), Close() => InvalidArgument()
   42         }
   43       } else if problem.code == "digest_unavailable" { InitializationFailed() }
   44       else if problem.code == "digest_failed" { DigestFailed() }
   45       else if problem.code == "resource_limit" { ResourceLimit() }
   46       else if problem.code == "unsupported" || problem.code == "unsupported_host" { UnsupportedHost() }
   47       else { OtherFailure() }
   48       Error(Sha256Error(operation, kind, problem))
   49     }
   50   }
   51 }
   52 

Functions

[
  {
    "id": "declaration/4",
    "name": "$owned$Sha256Error$render",
    "line": 10,
    "state": "covered",
    "entries": "14"
  },
  {
    "id": "declaration/5",
    "name": "convert",
    "line": 33,
    "state": "covered",
    "entries": "45"
  }
]

Source branch outcomes

[
  {
    "id": "declaration/4/statement/0/value/arm/0",
    "outcome": "Create",
    "line": 12,
    "state": "covered",
    "hits": "2"
  },
  {
    "id": "declaration/4/statement/0/value/arm/1",
    "outcome": "Update",
    "line": 13,
    "state": "covered",
    "hits": "3"
  },
  {
    "id": "declaration/4/statement/0/value/arm/2",
    "outcome": "Finish",
    "line": 14,
    "state": "covered",
    "hits": "1"
  },
  {
    "id": "declaration/4/statement/0/value/arm/3",
    "outcome": "Close",
    "line": 15,
    "state": "covered",
    "hits": "8"
  },
  {
    "id": "declaration/4/statement/1/value/arm/0",
    "outcome": "InvalidContext",
    "line": 18,
    "state": "covered",
    "hits": "1"
  },
  {
    "id": "declaration/4/statement/1/value/arm/1",
    "outcome": "ChunkTooLarge",
    "line": 19,
    "state": "covered",
    "hits": "3"
  },
  {
    "id": "declaration/4/statement/1/value/arm/2",
    "outcome": "InvalidArgument",
    "line": 20,
    "state": "covered",
    "hits": "1"
  },
  {
    "id": "declaration/4/statement/1/value/arm/3",
    "outcome": "InitializationFailed",
    "line": 21,
    "state": "covered",
    "hits": "2"
  },
  {
    "id": "declaration/4/statement/1/value/arm/4",
    "outcome": "DigestFailed",
    "line": 22,
    "state": "covered",
    "hits": "1"
  },
  {
    "id": "declaration/4/statement/1/value/arm/5",
    "outcome": "ResourceLimit",
    "line": 23,
    "state": "covered",
    "hits": "1"
  },
  {
    "id": "declaration/4/statement/1/value/arm/6",
    "outcome": "UnsupportedHost",
    "line": 24,
    "state": "covered",
    "hits": "4"
  },
  {
    "id": "declaration/4/statement/1/value/arm/7",
    "outcome": "OtherFailure",
    "line": 25,
    "state": "covered",
    "hits": "1"
  },
  {
    "id": "declaration/4/statement/3/value/decision/true",
    "outcome": "true",
    "line": 28,
    "state": "covered",
    "hits": "6"
  },
  {
    "id": "declaration/4/statement/3/value/decision/false",
    "outcome": "false",
    "line": 28,
    "state": "covered",
    "hits": "8"
  },
  {
    "id": "declaration/5/tail/arm/0",
    "outcome": "Ok",
    "line": 35,
    "state": "covered",
    "hits": "23"
  },
  {
    "id": "declaration/5/tail/arm/1",
    "outcome": "Error",
    "line": 36,
    "state": "covered",
    "hits": "22"
  },
  {
    "id": "declaration/5/tail/arm/1/body/block/statement/0/value/decision/true",
    "outcome": "true",
    "line": 37,
    "state": "covered",
    "hits": "7"
  },
  {
    "id": "declaration/5/tail/arm/1/body/block/statement/0/value/decision/false",
    "outcome": "false",
    "line": 37,
    "state": "covered",
    "hits": "15"
  },
  {
    "id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/decision/true",
    "outcome": "true",
    "line": 38,
    "state": "covered",
    "hits": "7"
  },
  {
    "id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/decision/false",
    "outcome": "false",
    "line": 38,
    "state": "covered",
    "hits": "8"
  },
  {
    "id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/true/tail/arm/0",
    "outcome": "Update",
    "line": 40,
    "state": "covered",
    "hits": "4"
  },
  {
    "id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/true/tail/arm/0/body/decision/true",
    "outcome": "true",
    "line": 40,
    "state": "covered",
    "hits": "3"
  },
  {
    "id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/true/tail/arm/0/body/decision/false",
    "outcome": "false",
    "line": 40,
    "state": "covered",
    "hits": "1"
  },
  {
    "id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/true/tail/arm/1",
    "outcome": "Create",
    "line": 41,
    "state": "covered",
    "hits": "1"
  },
  {
    "id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/true/tail/arm/2",
    "outcome": "Finish",
    "line": 41,
    "state": "covered",
    "hits": "1"
  },
  {
    "id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/true/tail/arm/3",
    "outcome": "Close",
    "line": 41,
    "state": "covered",
    "hits": "1"
  },
  {
    "id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/decision/true",
    "outcome": "true",
    "line": 43,
    "state": "covered",
    "hits": "1"
  },
  {
    "id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/decision/false",
    "outcome": "false",
    "line": 43,
    "state": "covered",
    "hits": "7"
  },
  {
    "id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/decision/true",
    "outcome": "true",
    "line": 44,
    "state": "covered",
    "hits": "1"
  },
  {
    "id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/decision/false",
    "outcome": "false",
    "line": 44,
    "state": "covered",
    "hits": "6"
  },
  {
    "id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/false/tail/decision/true",
    "outcome": "true",
    "line": 45,
    "state": "covered",
    "hits": "1"
  },
  {
    "id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/false/tail/decision/false",
    "outcome": "false",
    "line": 45,
    "state": "covered",
    "hits": "5"
  },
  {
    "id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/false/tail/false/tail/decision/true",
    "outcome": "true",
    "line": 46,
    "state": "covered",
    "hits": "2"
  },
  {
    "id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/false/tail/false/tail/decision/false",
    "outcome": "false",
    "line": 46,
    "state": "covered",
    "hits": "3"
  },
  {
    "id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/false/tail/false/tail/condition/decision/evaluate-right",
    "outcome": "evaluate-right",
    "line": 46,
    "state": "covered",
    "hits": "4"
  },
  {
    "id": "declaration/5/tail/arm/1/body/block/statement/0/value/false/tail/false/tail/false/tail/false/tail/false/tail/condition/decision/skip-right",
    "outcome": "skip-right",
    "line": 46,
    "state": "covered",
    "hits": "1"
  }
]

Reviewed declaration exclusions

[
  {
    "id": "declaration/0",
    "reason": "import",
    "line": 1
  },
  {
    "id": "declaration/1",
    "reason": "enum-declaration",
    "line": 2
  },
  {
    "id": "declaration/2",
    "reason": "enum-declaration",
    "line": 3
  },
  {
    "id": "declaration/3",
    "reason": "record-declaration",
    "line": 7
  }
]