aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--matrix-json.c31
-rw-r--r--matrix-json.h8
2 files changed, 39 insertions, 0 deletions
diff --git a/matrix-json.c b/matrix-json.c
index e49176e..dcbb0bd 100644
--- a/matrix-json.c
+++ b/matrix-json.c
@@ -232,6 +232,37 @@ GString *matrix_canonical_json(JsonObject *object)
return canonical_json_object(object, NULL);
}
+/* Decode a json web signature (JWS) which is almost base64,
+ * its needs _ -> / and - -> + and some = padding.
+ * as https://tools.ietf.org/html/draft-ietf-jose-json-web-signature-41#appendix-C
+ * The output buffer should be upto 3 bytes longer than the input
+ * depending on the amount of = padding needed.
+ */
+void matrix_json_jws_tobase64(gchar *out, const gchar *in)
+{
+ unsigned int i;
+ for (i=0;in[i];i++) {
+ out[i] = in[i];
+ switch (in[i]) {
+ case '-':
+ out[i] = '+';
+ break;
+
+ case '_':
+ out[i] = '/';
+ break;
+
+ default:
+ break;
+ }
+ }
+ while (i & 3) {
+ out[i] = '=';
+ i++;
+ }
+ out[i] = '\0';
+}
+
/* Just dump the Json with the string prefix for debugging */
void matrix_debug_jsonobject(const char *reason, JsonObject *object)
{
diff --git a/matrix-json.h b/matrix-json.h
index 43b94aa..8aed2d1 100644
--- a/matrix-json.h
+++ b/matrix-json.h
@@ -65,6 +65,14 @@ const gchar *matrix_json_array_get_string_element(JsonArray *array,
*/
GString *matrix_canonical_json(JsonObject *object);
+/* Decode a json web signature (JWS) which is almost base64,
+ * its needs _ -> / and - -> + and some = padding.
+ * as https://tools.ietf.org/html/draft-ietf-jose-json-web-signature-41#appendix-C
+ * The output buffer should be upto 3 bytes longer than the input
+ * depending on the amount of = padding needed.
+ */
+void matrix_json_jws_tobase64(gchar *out, const gchar *in);
+
/* Just dump the Json with the string prefix for debugging */
void matrix_debug_jsonobject(const char *reason, JsonObject *object);