Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation #10

Merged
merged 4 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.nr linguist-language=rust
marekkirejczyk marked this conversation as resolved.
Show resolved Hide resolved

23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,29 @@ Library exposes two functions:

```rust
pub fn encode_str<N, M>(input: str<N>, mut result: [u8; M]) -> [u8; M]
pub fn encode<N, M>(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<N, M>(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

Expand Down
2 changes: 1 addition & 1 deletion examples/base64_example/Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
2 changes: 1 addition & 1 deletion examples/base64_example/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down