From 3bab48000c4e61104b30ac379806cad3e1376ea6 Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Wed, 25 Jan 2017 15:54:40 +0100 Subject: common: Add path encoding functions This adds p11_path_{encode,decode}(), following the escaping rule described in: https://dbus.freedesktop.org/doc/dbus-specification.html#addresses Although they are merely a wrapper around p11_url_{decode,encode}(), having dedicated functions hides the implementation details. --- common/test-path.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'common/test-path.c') diff --git a/common/test-path.c b/common/test-path.c index 1394e0f..c77acf2 100644 --- a/common/test-path.c +++ b/common/test-path.c @@ -200,6 +200,26 @@ test_canon (void) free (test); } +static void +test_encode (void) +{ + char *test; + + test = p11_path_encode ("2309haonutb;/AOE@#$O "); + assert_str_eq (test, "2309haonutb%3b/AOE%40%23%24O%20"); + free (test); +} + +static void +test_decode (void) +{ + char *test; + + test = p11_path_decode ("2309haonutb%3b/AOE%40%23%24O%20"); + assert_str_eq (test, "2309haonutb;/AOE@#$O "); + free (test); +} + int main (int argc, char *argv[]) @@ -211,6 +231,8 @@ main (int argc, p11_test (test_parent, "/path/parent"); p11_test (test_prefix, "/path/prefix"); p11_test (test_canon, "/path/canon"); + p11_test (test_encode, "/path/encode"); + p11_test (test_decode, "/path/decode"); return p11_test_run (argc, argv); } -- cgit v1.1