diff options
| author | Charles.Forsyth <devnull@localhost> | 2008-01-16 01:19:38 +0000 |
|---|---|---|
| committer | Charles.Forsyth <devnull@localhost> | 2008-01-16 01:19:38 +0000 |
| commit | ca1042d3d05e5e9b2b5094b04197c96ec3b34bfe (patch) | |
| tree | 6a2cb733509e5a3692efa952e1c3bc5503c25355 /appl/lib | |
| parent | e84ac69296d2bd901d9d5dba59a1873fc6fb7cc1 (diff) | |
20080116-0125
Diffstat (limited to 'appl/lib')
| -rw-r--r-- | appl/lib/factotum.b | 120 | ||||
| -rw-r--r-- | appl/lib/spki/spki.b | 50 |
2 files changed, 153 insertions, 17 deletions
diff --git a/appl/lib/factotum.b b/appl/lib/factotum.b index a2cec879..0b3ff1a8 100644 --- a/appl/lib/factotum.b +++ b/appl/lib/factotum.b @@ -306,3 +306,123 @@ getuserpasswd(keyspec: string): (string, string) } return (hd flds, hd tl flds); } + +parseattrs(s: string): list of ref Attr +{ + str := load String String->PATH; + fld := str->unquoted(s); + rfld := fld; + for(fld = nil; rfld != nil; rfld = tl rfld) + fld = (hd rfld) :: fld; + attrs: list of ref Attr; + for(; fld != nil; fld = tl fld){ + n := hd fld; + a := ""; + tag := Aattr; + for(i:=0; i<len n; i++) + if(n[i] == '='){ + a = n[i+1:]; + n = n[0:i]; + tag = Aval; + } + if(len n == 0) + continue; + if(tag == Aattr && len n > 1 && n[len n-1] == '?'){ + tag = Aquery; + n = n[0:len n-1]; + } + attrs = ref Attr(tag, n, a) :: attrs; + } + # TO DO: eliminate answered queries + return attrs; +} + +Attr.text(a: self ref Attr): string +{ + case a.tag { + Aattr => + return a.name; + Aval => + return sys->sprint("%q=%q", a.name, a.val); + Aquery => + return sys->sprint("%q?", a.name); + * => + return "??"; + } +} + +attrtext(attrs: list of ref Attr): string +{ + s := ""; + for(; attrs != nil; attrs = tl attrs){ + if(s != nil) + s[len s] = ' '; + s += (hd attrs).text(); + } + return s; +} + +findattr(attrs: list of ref Attr, n: string): ref Attr +{ + for(; attrs != nil; attrs = tl attrs) + if((a := hd attrs).tag != Aquery && a.name == n) + return a; + return nil; +} + +findattrval(attrs: list of ref Attr, n: string): string +{ + if((a := findattr(attrs, n)) != nil) + return a.val; + return nil; +} + +delattr(l: list of ref Attr, n: string): list of ref Attr +{ + rl: list of ref Attr; + for(; l != nil; l = tl l) + if((hd l).name != n) + rl = hd l :: rl; + return rev(rl); +} + +copyattrs(l: list of ref Attr): list of ref Attr +{ + rl: list of ref Attr; + for(; l != nil; l = tl l) + rl = hd l :: rl; + return rev(rl); +} + +takeattrs(l: list of ref Attr, names: list of string): list of ref Attr +{ + rl: list of ref Attr; + for(; l != nil; l = tl l){ + n := (hd l).name; + for(nl := names; nl != nil; nl = tl nl) + if((hd nl) == n){ + rl = hd l :: rl; + break; + } + } + return rev(rl); +} + +publicattrs(l: list of ref Attr): list of ref Attr +{ + rl: list of ref Attr; + for(; l != nil; l = tl l){ + a := hd l; + if(a.tag != Aquery || a.val == nil) + rl = a :: rl; + } + return rev(rl); +} + +rev[T](l: list of T): list of T +{ + rl: list of T; + for(; l != nil; l = tl l) + rl = hd l :: rl; + return rl; +} diff --git a/appl/lib/spki/spki.b b/appl/lib/spki/spki.b index 18a2d68a..615aa48e 100644 --- a/appl/lib/spki/spki.b +++ b/appl/lib/spki/spki.b @@ -629,7 +629,7 @@ signbytes(data: array of byte, sigalg: string, key: ref Key): (ref Signature, st l: list of (string, array of byte); for(; vals != nil; vals = tl vals){ (n, v) := hd vals; - l = (f2s(n), v) :: l; + l = (f2s("rsa", n), v) :: l; } sig.sig = revt(l); return (sig, nil); @@ -1095,7 +1095,7 @@ Key.sexp(k: self ref Key): ref Sexp for(; els != nil; els = tl els){ (n, v) := hd els; a := pre0(v.iptobebytes()); - rl = ref Sexp.List(ref Sexp.String(f2s(n),nil) :: ref Sexp.Binary(a,nil) :: nil) :: rl; + rl = ref Sexp.List(ref Sexp.String(f2s("rsa", n),nil) :: ref Sexp.Binary(a,nil) :: nil) :: rl; } return ref Sexp.List(ref Sexp.String(sort, nil) :: ref Sexp.List(ref Sexp.String(k.sigalg(),nil) :: rev(rl)) :: nil); @@ -2093,9 +2093,12 @@ Keyrep.pk(pk: ref Keyring->PK): ref Keyrep.PK "rsa" => return ref Keyrep.PK(hd flds, hd tl flds, keyextract(tl tl flds, list of {("ek",1), ("n",0)})); - "elgamal" or "dsa" => + "elgamal" => return ref Keyrep.PK(hd flds, hd tl flds, keyextract(tl tl flds, list of {("p",0), ("alpha",1), ("key",2)})); + "dsa" => + return ref Keyrep.PK(hd flds, hd tl flds, + keyextract(tl tl flds, list of {("p",0), ("alpha",2), ("q",1), ("key",3)})); * => return nil; } @@ -2112,9 +2115,12 @@ Keyrep.sk(pk: ref Keyring->SK): ref Keyrep.SK "rsa" => return ref Keyrep.SK(hd flds, hd tl flds, keyextract(tl tl flds,list of {("ek",1), ("n",0), ("!dk",2), ("!q",4), ("!p",3), ("!kq",6), ("!kp",5), ("!c2",7)})); # see comment elsewhere about p, q - "elgamal" or "dsa" => + "elgamal" => return ref Keyrep.SK(hd flds, hd tl flds, keyextract(tl tl flds, list of {("p",0), ("alpha",1), ("key",2), ("!secret",3)})); + "dsa" => + return ref Keyrep.SK(hd flds, hd tl flds, + keyextract(tl tl flds, list of {("p",0), ("alpha",2), ("q",1), ("key",3), ("!secret",4)})); * => return nil; } @@ -2122,7 +2128,7 @@ Keyrep.sk(pk: ref Keyring->SK): ref Keyrep.SK Keyrep.get(k: self ref Keyrep, n: string): ref IPint { - n1 := f2s(n); + n1 := f2s("rsa", n); for(el := k.els; el != nil; el = tl el) if((hd el).t0 == n || (hd el).t0 == n1) return (hd el).t1; @@ -2191,21 +2197,31 @@ s2f(s: string): string } } -f2s(s: string): string +f2s(alg: string, s: string): string { - case s { - "ek" => return "e"; - "!p" => return "q"; # see above - "!q" => return "p"; - "!dk" => return "d"; - "!kp" => return "b"; - "!kq" => return "a"; - "!c2" => return "c"; + case alg { + "rsa" => + case s { + "ek" => return "e"; + "!p" => return "q"; # see above + "!q" => return "p"; + "!dk" => return "d"; + "!kp" => return "b"; + "!kq" => return "a"; + "!c2" => return "c"; + } + "dsa" => + case s { + "p" or "q" => return s; + "alpha" => return "g"; + "key" => return "y"; + } * => - if(s != nil && s[0] == '!') - return s[1:]; - return s; + ; } + if(s != nil && s[0] == '!') + return s[1:]; + return s; } Keyrep.eq(k1: self ref Keyrep, k2: ref Keyrep): int |
