diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..a8654f4 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +*.nr linguist-language=rust + diff --git a/README.md b/README.md index d009c37..fc274fc 100644 --- a/README.md +++ b/README.md @@ -28,18 +28,29 @@ Library exposes two functions: ```rust pub fn encode_str(input: str, mut result: [u8; M]) -> [u8; M] -pub fn encode(input: [u8; N], mut result: [u8; M], url_safe: bool) -> [u8; M] ``` -- `input` - input string or array of bytes to encode. Max input length is 600. -- `result` - array of bytes to store result in. it should have a proper size otherwise function will fail on assert. +- `input` - string to encode. Max string length is 600. +- `result` - array of bytes to store result in. It should have a proper size otherwise function will fail on assert. Due to Noir language limitations result size need to be known at compile time and should be calculated by user. - Value of this parameter is irrelevant, only size matters. + Value of this parameter are irrelevant, only size matters. +- Returns `result` array with encoded string. Function result is also stored in mutable `result` array argument. + +```rust +pub fn encode(input: [u8; N], mut result: [u8; M], url_safe: bool) -> [u8; M] +``` + +- `input` - array of bytes to encode. Max array size is 600. +- `result` - array of bytes to store result in. It should have a proper size otherwise function will fail on assert. + Due to Noir language limitations result size need to be known at compile time and should be calculated by user. + Values in this array are irrelevant, only size matters. - `url_safe` - if `true` then `+` and `/` characters will be replaced with `-` and `_` respectively ([RFC4648](https://datatracker.ietf.org/doc/html/rfc4648#section-5)) -- Returns `result` array with encoded string. Function result is the same as `result` argument. +- Returns `result` array with encoded string. Function result is also stored in mutable `result` array argument. + +Base64 **decoding** is not supported yet. Will be implemented in future releases. ## Example project -Directory `examples/base64_example/` contains example Noir project with `base64` library as dependency. +Directory [examples/base64_example/](https://github.com/zkworks-xyz/noir-base64/tree/main/examples/base64_example) contains example Noir project with `base64` library as dependency. ## License diff --git a/examples/base64_example/Nargo.toml b/examples/base64_example/Nargo.toml index 10ed5fa..62a0c74 100644 --- a/examples/base64_example/Nargo.toml +++ b/examples/base64_example/Nargo.toml @@ -5,4 +5,4 @@ authors = [""] compiler_version = ">=0.19.2" [dependencies] -base64 = { tag = "v0.1.0", git = "https://github.com/zkworks-xyz/noir-base64" } +base64 = { tag = "v0.1.1", git = "https://github.com/zkworks-xyz/noir-base64" } diff --git a/examples/base64_example/src/main.nr b/examples/base64_example/src/main.nr index 77c3971..e826819 100644 --- a/examples/base64_example/src/main.nr +++ b/examples/base64_example/src/main.nr @@ -2,7 +2,7 @@ use dep::base64; use dep::std; fn main() { - let result: [u8; 8] = base64::encode_str("foobar", [0; 8], false); + let result: [u8; 8] = base64::encode_str("foobar", [0; 8]); std::println(result); }