Skip to content

Can some error results be merged or replaced with panics? #85

@fjarri

Description

@fjarri

At the moment umbral is designed to never panic and always return a Result/Option. In some cases this results in rather silly errors that, if happen, are not something one can recover from, but rather indicate a bug in the rust-umbral, or the calling code. Perhaps we can introduce some panics to simplify the API. Although we need to remember that rust-umbral may be run in embedded environments.

Additional reading:
https://doc.rust-lang.org/book/ch09-03-to-panic-or-not-to-panic.html
https://www.unwoundstack.com/blog/rust-error-handling.html

A (perhaps non-exhaustive) list of candidates for replacement with panic:

  • OpenReencryptedError::NoCapsuleFrags - the caller should ensure that the list of cfrags is not empty
  • OpenReencryptedError::ZeroHash - very low probability of happening either randomly or intentionally (caused by some malicious actor)
  • SecretKeyFactoryError::ZeroHash - see above.
  • EncryptionError::PlaintextTooLarge - this is basically an OOM situation. In all other cases of OOM the code will panic anyway. For embedded environments we may provide an infallible encrypt_to_buffer or something.

Some errors may be merged, since they are effectively the same from the user's point of view:

  • IncorrectKeyFragSignature and IncorrectReencryption in CapsuleFragVerificationError
  • CiphertextTooShort and AuthenticationFailed in DecryptionError
  • IncorrectCommitment and IncorrectSignature in KeyFragVerificationError. Possibly merged with DelegatingKeyNotProvided and ReceivingKeyNotProvided too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    APIRelated to public API

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions