This commit is contained in:
Miek Gieben 2011-12-16 14:48:30 +01:00
parent a9e3ec9880
commit ef7b6f525f
5 changed files with 60 additions and 60 deletions

View File

@ -113,27 +113,27 @@ func (r *RR_DNSKEY) PrivateKeyString(p PrivateKey) (s string) {
// ReadPrivateKey reads a private key from the io.Reader q.
func (k *RR_DNSKEY) ReadPrivateKey(q io.Reader) (PrivateKey, error) {
/*
p := NewParser(q)
kv, _ := p.PrivateKey()
if kv == nil {
/*
p := NewParser(q)
kv, _ := p.PrivateKey()
if kv == nil {
return nil, ErrPrivKey
}
if _, ok := kv["private-key-format"]; !ok {
return nil, ErrPrivKey
}
if kv["private-key-format"] != "v1.2" && kv["private-key-format"] != "v1.3" {
return nil, ErrPrivKey
}
switch kv["algorithm"] {
case "RSAMD5", "RSASHA1", "RSASHA256", "RSASHA512":
return k.readPrivateKeyRSA(kv)
case "ECDSAP256SHA256", "ECDSAP384SHA384":
return k.readPrivateKeyECDSA(kv)
}
return nil, ErrPrivKey
}
if _, ok := kv["private-key-format"]; !ok {
return nil, ErrPrivKey
}
if kv["private-key-format"] != "v1.2" && kv["private-key-format"] != "v1.3" {
return nil, ErrPrivKey
}
switch kv["algorithm"] {
case "RSAMD5", "RSASHA1", "RSASHA256", "RSASHA512":
return k.readPrivateKeyRSA(kv)
case "ECDSAP256SHA256", "ECDSAP384SHA384":
return k.readPrivateKeyECDSA(kv)
}
return nil, ErrPrivKey
*/
return nil, nil
*/
return nil, nil
}
// Read a private key (file) string and create a public key. Return the private key.

View File

@ -9,24 +9,24 @@ import (
// channel cr. The channel cr is closed by ParseZone when the end of r is reached.
func ParseKey(r io.Reader) (map[string]string, error) {
var s scanner.Scanner
m := make(map[string]string)
m := make(map[string]string)
c := make(chan Lex)
k := ""
k := ""
s.Init(r)
s.Mode = 0
s.Whitespace = 0
// Start the lexer
go klexer(s, c)
for l := range c {
// It should alternate
// It should alternate
switch l.value {
case _KEY:
k = l.token
k = l.token
case _VALUE:
m[k] = l.token
m[k] = l.token
}
}
return m, nil
return m, nil
}
// klexer scans the sourcefile and returns tokens on the channel c.
@ -34,24 +34,24 @@ func klexer(s scanner.Scanner, c chan Lex) {
var l Lex
str := "" // Hold the current read text
commt := false
key := true
key := true
tok := s.Scan()
defer close(c)
for tok != scanner.EOF {
l.column = s.Position.Column
l.line = s.Position.Line
switch x := s.TokenText(); x {
case ":":
case ":":
if commt {
break
}
if key {
l.value = _KEY
c <- l
key = false
} else {
l.value = _VALUE
}
if key {
l.value = _KEY
c <- l
key = false
} else {
l.value = _VALUE
}
case ";":
commt = true
case "\n":
@ -59,10 +59,10 @@ func klexer(s scanner.Scanner, c chan Lex) {
// Reset a comment
commt = false
}
c <- l
c <- l
str = ""
commt = false
key = true
key = true
default:
if commt {
break

View File

@ -796,7 +796,7 @@ func (rr *RR_TSIG) String() string {
func timeToDate(t uint32) string {
utc := time.Now().Unix()
mod := (int64(t) - utc) / Year68
ti := time.Unix(time.Unix(int64(t),0).Unix() + (mod * Year68), 0) // abs()? TODO
ti := time.Unix(time.Unix(int64(t), 0).Unix()+(mod*Year68), 0) // abs()? TODO
return ti.Format("20060102150405")
}
@ -804,13 +804,13 @@ func timeToDate(t uint32) string {
// string values ("20110403154150") to an integer.
// Taking into account serial arithmetic (RFC 1982)
func dateToTime(s string) (uint32, error) {
t, e := time.Parse("20060102150405", s)
if e != nil {
return 0, e
}
mod := t.Unix() / Year68
ti := uint32(t.Unix() - (mod * Year68))
return ti, nil
t, e := time.Parse("20060102150405", s)
if e != nil {
return 0, e
}
mod := t.Unix() / Year68
ti := uint32(t.Unix() - (mod * Year68))
return ti, nil
}
// Translate the TSIG time signed into a date. There is no
@ -819,8 +819,8 @@ func tsigTimeToDate(t uint64) string {
// only use the lower 48 bits, TODO(mg), check for 48 bit size
return ""
/*
ti := time.Unix(int64(t), 0).Unix()
return ti.Format("20060102150405")
ti := time.Unix(int64(t), 0).Unix()
return ti.Format("20060102150405")
*/
}

View File

@ -49,10 +49,10 @@ type ParseError struct {
}
func (e *ParseError) Error() string {
va := strconv.Itoa(e.lex.value)
s := e.err + ": `" + e.lex.token + "' (value: " + va + ") at line: " +
strconv.Itoa(e.lex.line) + " and column: " +
strconv.Itoa(e.lex.column)
va := strconv.Itoa(e.lex.value)
s := e.err + ": `" + e.lex.token + "' (value: " + va + ") at line: " +
strconv.Itoa(e.lex.line) + " and column: " +
strconv.Itoa(e.lex.column)
return s
}
@ -64,7 +64,7 @@ type Lex struct {
}
type Token struct {
Rr RR // the scanned resource record
Rr RR // the scanned resource record
Error *ParseError // when an error occured, this is the specifics
}
@ -222,11 +222,11 @@ func ParseZone(r io.Reader, t chan Token) {
// I could save my token here...? l
r, e := setRR(h, c)
if e != nil {
// If e.Lex is nil than we have encounter a unknown RR type
// in that case we substitute our current Lex token
if e.lex.token == "" && e.lex.value == 0 {
e.lex = l // Uh, dirty
}
// If e.Lex is nil than we have encounter a unknown RR type
// in that case we substitute our current Lex token
if e.lex.token == "" && e.lex.value == 0 {
e.lex = l // Uh, dirty
}
t <- Token{Error: e}
return
}

View File

@ -17,7 +17,7 @@ func setRR(h RR_Header, c chan Lex) (RR, *ParseError) {
var r RR
e := new(ParseError)
switch h.Rrtype {
// goto Slurpremainder
// goto Slurpremainder
case TypeA:
r, e = setA(h, c)
if e != nil {
@ -294,7 +294,7 @@ func setRRSIG(h RR_Header, c chan Lex) (RR, *ParseError) {
}
// Get the remaining data until we see a NEWLINE
l = <-c
s := ""
s := ""
for l.value != _NEWLINE && l.value != _EOF {
switch l.value {
case _STRING:
@ -511,7 +511,7 @@ func setDS(h RR_Header, c chan Lex) (RR, *ParseError) {
}
// There can be spaces here...
l = <-c
s := ""
s := ""
for l.value != _NEWLINE && l.value != _EOF {
switch l.value {
case _STRING: