Git Product home page Git Product logo

Comments (3)

briansmith avatar briansmith commented on May 11, 2024 1

Another option, which I saw in another library and I think is nice, is to define a new type for each kind of argument. For example, we currently have:

pub fn verify(alg: &VerificationAlgorithm, public_key: Input,
              msg: Input, signature: Input) -> Result<(), Unspecified> { ... }

But, we could instead:

enum EncodedPublicKey(untrusted::Input);
enum Signed(untrusted::Input);
enum EncodedSignature(untrusted::Input);

pub fn verify(alg: &VerificationAlgorithm, public_key: EncodedPublicKey,
              msg: Signed, signature: EncodedSignature) -> Result<(), Unspecified> { ... }

Pros of such a change:

  • It would be much harder for the caller to confuse one input argument for another.
  • Future (breaking) changes to the API are likely to result in more compile-time failures and fewer (near zero) runtime failures, which is what we want.

Cons of such a change:

  • If somebody isn't doing their parsing using untrusted.rs already, then they would have to wrap their &[u8] slices in both untrusted::Input and the wrapper type, which could get really annoying.

from ring.

briansmith avatar briansmith commented on May 11, 2024

Input & Reader were moved to ring a long time ago and then factors out into untrusted.rs. We take inputs as untrusted::Input in several places. We need to comb through the API, especially older APIs, and change the ones that operate on untrusted inputs to take those as untrusted::Input.

from ring.

briansmith avatar briansmith commented on May 11, 2024

Not only did we do this, but everybody hates it. Oh well.

from ring.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.