scripts: Add -d option to oid2der to decode DER encoded OIDs
authorTobias Brunner <tobias@strongswan.org>
Wed, 18 Oct 2017 14:28:04 +0000 (16:28 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 2 Nov 2017 09:02:26 +0000 (10:02 +0100)
scripts/oid2der.c

index 793c980..c8ab8df 100644 (file)
@@ -23,9 +23,26 @@ int main(int argc, char *argv[])
 {
        int i, nr = 0;
        chunk_t oid;
+       char *decoded;
+       bool decode = FALSE;
+
+       if (streq(argv[1], "-d"))
+       {
+               decode = TRUE;
+               nr++;
+       }
 
        while (argc > ++nr)
        {
+               if (decode)
+               {
+                       oid = chunk_from_hex(chunk_from_str(argv[nr]), NULL);
+                       decoded = asn1_oid_to_string(oid);
+                       printf("%s\n", decoded);
+                       free(decoded);
+                       free(oid.ptr);
+                       continue;
+               }
                oid = asn1_oid_from_string(argv[nr]);
                if (oid.len)
                {