summaryrefslogtreecommitdiff
path: root/sys/src/libsec
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2015-10-09 18:52:32 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2015-10-09 18:52:32 +0200
commit9ec1a07af2537e5485524c8d079a07abfee6f96d (patch)
tree4f4b836d7ff23b81027f906235c12830c97eaf33 /sys/src/libsec
parent6bb63f78321a7c51beb88c1f340b333496d5f272 (diff)
libsec: clarify the code by declaring constant for DirectoryString and handle conversion in mkstring()
Diffstat (limited to 'sys/src/libsec')
-rw-r--r--sys/src/libsec/port/x509.c49
1 files changed, 26 insertions, 23 deletions
diff --git a/sys/src/libsec/port/x509.c b/sys/src/libsec/port/x509.c
index 19119b10f..aaecc314b 100644
--- a/sys/src/libsec/port/x509.c
+++ b/sys/src/libsec/port/x509.c
@@ -2357,11 +2357,31 @@ mkbigint(mpint *p)
return e;
}
+static int
+printable(char *s)
+{
+ int c;
+
+ while((c = (uchar)*s++) != 0){
+ if((c >= 'a' && c <= 'z')
+ || (c >= 'A' && c <= 'Z')
+ || (c >= '0' && c <= '9')
+ || strchr("'=()+,-./:? ", c) != nil)
+ continue;
+ return 0;
+ }
+ return 1;
+}
+
+#define DirectoryString 0
+
static Elem
mkstring(char *s, int t)
{
Elem e;
+ if(t == DirectoryString)
+ t = printable(s) ? PrintableString : UTF8String;
e.tag.class = Universal;
e.tag.num = t;
e.val.tag = VString;
@@ -2451,22 +2471,6 @@ mkalg(int alg)
return mkseq(mkel(mkoid(alg_oid_tab[alg]), mkel(Null(), nil)));
}
-static int
-printable(char *s)
-{
- int c;
-
- while((c = (uchar)*s++) != 0){
- if((c >= 'a' && c <= 'z')
- || (c >= 'A' && c <= 'Z')
- || (c >= '0' && c <= '9')
- || strchr("'=()+,-./:? ", c) != nil)
- continue;
- return 0;
- }
- return 1;
-}
-
typedef struct Ints7pref {
int len;
int data[7];
@@ -2475,11 +2479,11 @@ typedef struct Ints7pref {
} Ints7pref;
Ints7pref DN_oid[] = {
{4, 2, 5, 4, 6, 0, 0, 0, "C=", PrintableString},
- {4, 2, 5, 4, 8, 0, 0, 0, "ST=" },
- {4, 2, 5, 4, 7, 0, 0, 0, "L=" },
- {4, 2, 5, 4, 10, 0, 0, 0, "O=" },
- {4, 2, 5, 4, 11, 0, 0, 0, "OU=" },
- {4, 2, 5, 4, 3, 0, 0, 0, "CN=" },
+ {4, 2, 5, 4, 8, 0, 0, 0, "ST=",DirectoryString},
+ {4, 2, 5, 4, 7, 0, 0, 0, "L=", DirectoryString},
+ {4, 2, 5, 4, 10, 0, 0, 0, "O=", DirectoryString},
+ {4, 2, 5, 4, 11, 0, 0, 0, "OU=",DirectoryString},
+ {4, 2, 5, 4, 3, 0, 0, 0, "CN=",DirectoryString},
{7, 1,2,840,113549,1,9,1, "E=", IA5String},
{7, 0,9,2342,19200300,100,1,25, "DC=",IA5String},
};
@@ -2487,8 +2491,7 @@ Ints7pref DN_oid[] = {
static Elem
mkname(Ints7pref *oid, char *subj)
{
- int stype = oid->stype ? oid->stype : (printable(subj) ? PrintableString : UTF8String);
- return mkset(mkel(mkseq(mkel(mkoid((Ints*)oid), mkel(mkstring(subj, stype), nil))), nil));
+ return mkset(mkel(mkseq(mkel(mkoid((Ints*)oid), mkel(mkstring(subj, oid->stype), nil))), nil));
}
static Elem