-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(rest): encode waku message payload in base64
- Loading branch information
Showing
7 changed files
with
86 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{.push raises: [Defect].} | ||
|
||
import stew/[results, byteutils, base64] | ||
|
||
|
||
type Base64String* = distinct string | ||
|
||
|
||
proc encode*(t: type Base64String, value: string|seq[byte]): Base64String = | ||
let val = block: | ||
when value is string: | ||
toBytes(value) | ||
else: | ||
value | ||
Base64String(base64.encode(Base64, val)) | ||
|
||
proc decode*(t: Base64String): Result[seq[byte], cstring] = | ||
try: | ||
ok(base64.decode(Base64, string(t))) | ||
except: | ||
err("failed to decode base64 string") | ||
|
||
proc `$`*(t: Base64String): string {.inline.}= | ||
string(t) | ||
|
||
proc `==`*(lhs: Base64String|string, rhs: Base64String|string): bool {.inline.}= | ||
string(lhs) == string(rhs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{.push raises: [Defect].} | ||
|
||
import std/typetraits | ||
import | ||
std/typetraits, | ||
stew/results, | ||
chronicles, | ||
serialization, | ||
|