* rune = rune_from_base64(NULL, argv[2]);
* if (!rune)
* errx(1, "Bad rune");
- * restr = rune_restr_from_string(NULL, argv[3]);
+ * restr = rune_restr_from_string(NULL, argv[3], strlen(argv[3]));
* if (!restr)
* errx(1, "Bad restriction string");
* rune_add_restr(rune, restr);
}
struct rune_restr *rune_restr_from_string(const tal_t *ctx,
- const char *str)
+ const char *str,
+ size_t len)
{
- size_t len = strlen(str);
struct rune_restr *restr;
restr = rune_restr_decode(NULL, &str, &len);
to_wbuf("", 1, wbuf);
}
-struct rune *rune_from_base64(const tal_t *ctx, const char *str)
+struct rune *rune_from_base64n(const tal_t *ctx, const char *str, size_t len)
{
- size_t len;
+ size_t blen;
u8 *data;
struct rune *rune;
- data = tal_arr(NULL, u8, base64_decoded_length(strlen(str)) + 1);
+ data = tal_arr(NULL, u8, base64_decoded_length(len) + 1);
- len = base64_decode_using_maps(&base64_maps_urlsafe,
+ blen = base64_decode_using_maps(&base64_maps_urlsafe,
(char *)data, tal_bytelen(data),
- str, strlen(str));
- if (len == -1)
+ str, len);
+ if (blen == -1)
goto fail;
-
- if (len < 32)
+
+ if (blen < 32)
goto fail;
- data[len] = '\0';
+ data[blen] = '\0';
/* Sanity check that it's a valid string! */
- if (strlen((char *)data + 32) != len - 32)
+ if (strlen((char *)data + 32) != blen - 32)
goto fail;
rune = from_string(ctx, (const char *)data + 32, data);
return NULL;
}
+struct rune *rune_from_base64(const tal_t *ctx, const char *str)
+{
+ return rune_from_base64n(ctx, str, strlen(str));
+}
+
char *rune_to_base64(const tal_t *ctx, const struct rune *rune)
{
u8 hash32[32];
*/
struct rune *rune_from_base64(const tal_t *ctx, const char *str);
+/**
+ * rune_from_base64n - convert base64 string to rune.
+ * @ctx: context to allocate rune off.
+ * @str: base64 string.
+ * @len: length of @str.
+ *
+ * Returns NULL if it's malformed.
+ */
+struct rune *rune_from_base64n(const tal_t *ctx, const char *str, size_t len);
+
/**
* rune_to_base64 - convert run to base64 string.
* @ctx: context to allocate rune off.
* rune_restr_from_string - convenience routine to parse a single restriction.
* @ctx: context to allocate rune off.
* @str: the string of form "<field><cond><val>[|<field><cond><val>]*"
+ * @len: the length of @str.
*
- * This is really an internal routine, exposed for simple examples.
+ * This is useful for writing simple tests and making simple runes.
*/
struct rune_restr *rune_restr_from_string(const tal_t *ctx,
- const char *str);
-
+ const char *str,
+ size_t len);
#endif /* CCAN_RUNE_RUNE_H */