| 375 | } |
| 376 | |
| 377 | char *rune_to_base64(const tal_t *ctx, const struct rune *rune) |
| 378 | { |
| 379 | u8 hash32[32]; |
| 380 | char *ret; |
| 381 | size_t ret_len; |
| 382 | struct wbuf wbuf; |
| 383 | |
| 384 | /* We're going to prepend hash */ |
| 385 | wbuf.off = sizeof(hash32); |
| 386 | wbuf.len = 64; |
| 387 | wbuf.buf = tal_arr(NULL, char, wbuf.len); |
| 388 | |
| 389 | to_string(&wbuf, rune, hash32); |
| 390 | /* Prepend hash */ |
| 391 | memcpy(wbuf.buf, hash32, sizeof(hash32)); |
| 392 | |
| 393 | ret = tal_arr(ctx, char, base64_encoded_length(wbuf.off) + 1); |
| 394 | ret_len = base64_encode_using_maps(&base64_maps_urlsafe, |
| 395 | ret, tal_bytelen(ret), |
| 396 | wbuf.buf, wbuf.off - 1); |
| 397 | ret[ret_len] = '\0'; |
| 398 | tal_free(wbuf.buf); |
| 399 | return ret; |
| 400 | } |
| 401 | |
| 402 | struct rune *rune_from_string(const tal_t *ctx, const char *str) |
| 403 | { |