Git Product home page Git Product logo

sfv's People

Contributors

cybai avatar emilio avatar glandium avatar hoverbear avatar lpardue avatar pyfisch avatar undef1nd avatar valenting avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

sfv's Issues

Basic deserailizing type checking

I feel pretty dumb asking this.

So I want to use the crate to help me handle Extensible Priorities headers, which is a set of priority parameters encoded as a Structured Headers Dictionary.

So far we have defined two parameters, u is an sh-integer, and i is a sh-boolean. When I parse this I want to ensure that the parameters are the expected type.

Take this example

fn main() {
    let ext_priority = "u=2,i";
    let dict = Parser::parse_dictionary(ext_priority.as_bytes());
    assert!(dict.is_ok());
    println!("{:#?}", dict);
}

prints:

Ok(
    {
        "u": Item(
            Item {
                bare_item: Integer(
                    2,
                ),
                params: {},
            },
        ),
        "i": Item(
            Item {
                bare_item: Boolean(
                    true,
                ),
                params: {},
            },
        ),
    },
)

great, it works!

But if I modify the input slightly to change the contents of u

fn main() {
    let ext_priority = "u=ohnoibrokeit,i";
    let dict = Parser::parse_dictionary(ext_priority.as_bytes());
    assert!(dict.is_ok());
    println!("{:#?}", dict);
}

prints:

Ok(
    {
        "u": Item(
            Item {
                bare_item: Token(
                    "ohnoibrokeit",
                ),
                params: {},
            },
        ),
        "i": Item(
            Item {
                bare_item: Boolean(
                    true,
                ),
                params: {},
            },
        ),
    },
)

The parser reads this as sh-token, not sh-integer.

How can I do some basic type checking of the parsing result?

Validation of Items on local contruction

sfv implements parsing validation, per the rules in RFC 8941. For example, Tokens are checked for valid character usage in https://github.com/undef1nd/sfv/blob/master/src/parser.rs#L290

However, I might have missed it but there doesn't appear to be an equivalent validation in the library when constructing such items. It seems like it would be helpful to support this, without having to resort to construction, serialization, and parsing.

For instance, the backing type to Token is String. And the docs suggest that I could create an Item of type Token by using

let token = BareItem::Token("12345");

This would strictly be an invalid token according to https://www.rfc-editor.org/rfc/rfc8941.html#section-3.3.4-7 - the first character is required to be either ALPHA or "*"

Of course, we could require that implementations sanitize their own values before passing into sfv. But then, sfv already implements the checks, just they aren't exposed in an easy way. It would be great to expose them for reuse.

The use case here is applications that pass through values from other things. If the receiving endpoint fails to parse that it will cause interop issues. It would be muc better if the sender had an opportunity to validate things before sending them, so that it might take mitigating action. There are probably still cases where a sender doesn't care, so perhaps checked and unchecked variants are required.

Are there C bindings?

I heard that this crate was used in Firefox and so I wondered if there are bindings to C or C++.

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.