Skip to content

Commit

Permalink
Documentation (#10)
Browse files Browse the repository at this point in the history
* Readme update

* Update example to version `v0.1.1`

* Configure .gitattributes

* decoding info
  • Loading branch information
akonior authored Nov 28, 2023
1 parent a41959a commit ee90be4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
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

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

0 comments on commit ee90be4

Please sign in to comment.