gofmt
This commit is contained in:
parent
a9e3ec9880
commit
ef7b6f525f
40
keygen.go
40
keygen.go
|
@ -113,27 +113,27 @@ func (r *RR_DNSKEY) PrivateKeyString(p PrivateKey) (s string) {
|
||||||
|
|
||||||
// ReadPrivateKey reads a private key from the io.Reader q.
|
// ReadPrivateKey reads a private key from the io.Reader q.
|
||||||
func (k *RR_DNSKEY) ReadPrivateKey(q io.Reader) (PrivateKey, error) {
|
func (k *RR_DNSKEY) ReadPrivateKey(q io.Reader) (PrivateKey, error) {
|
||||||
/*
|
/*
|
||||||
p := NewParser(q)
|
p := NewParser(q)
|
||||||
kv, _ := p.PrivateKey()
|
kv, _ := p.PrivateKey()
|
||||||
if kv == nil {
|
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
|
return nil, ErrPrivKey
|
||||||
}
|
*/
|
||||||
if _, ok := kv["private-key-format"]; !ok {
|
return nil, nil
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read a private key (file) string and create a public key. Return the private key.
|
// Read a private key (file) string and create a public key. Return the private key.
|
||||||
|
|
34
kscan.go
34
kscan.go
|
@ -9,24 +9,24 @@ import (
|
||||||
// channel cr. The channel cr is closed by ParseZone when the end of r is reached.
|
// 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) {
|
func ParseKey(r io.Reader) (map[string]string, error) {
|
||||||
var s scanner.Scanner
|
var s scanner.Scanner
|
||||||
m := make(map[string]string)
|
m := make(map[string]string)
|
||||||
c := make(chan Lex)
|
c := make(chan Lex)
|
||||||
k := ""
|
k := ""
|
||||||
s.Init(r)
|
s.Init(r)
|
||||||
s.Mode = 0
|
s.Mode = 0
|
||||||
s.Whitespace = 0
|
s.Whitespace = 0
|
||||||
// Start the lexer
|
// Start the lexer
|
||||||
go klexer(s, c)
|
go klexer(s, c)
|
||||||
for l := range c {
|
for l := range c {
|
||||||
// It should alternate
|
// It should alternate
|
||||||
switch l.value {
|
switch l.value {
|
||||||
case _KEY:
|
case _KEY:
|
||||||
k = l.token
|
k = l.token
|
||||||
case _VALUE:
|
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.
|
// 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
|
var l Lex
|
||||||
str := "" // Hold the current read text
|
str := "" // Hold the current read text
|
||||||
commt := false
|
commt := false
|
||||||
key := true
|
key := true
|
||||||
tok := s.Scan()
|
tok := s.Scan()
|
||||||
defer close(c)
|
defer close(c)
|
||||||
for tok != scanner.EOF {
|
for tok != scanner.EOF {
|
||||||
l.column = s.Position.Column
|
l.column = s.Position.Column
|
||||||
l.line = s.Position.Line
|
l.line = s.Position.Line
|
||||||
switch x := s.TokenText(); x {
|
switch x := s.TokenText(); x {
|
||||||
case ":":
|
case ":":
|
||||||
if commt {
|
if commt {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if key {
|
if key {
|
||||||
l.value = _KEY
|
l.value = _KEY
|
||||||
c <- l
|
c <- l
|
||||||
key = false
|
key = false
|
||||||
} else {
|
} else {
|
||||||
l.value = _VALUE
|
l.value = _VALUE
|
||||||
}
|
}
|
||||||
case ";":
|
case ";":
|
||||||
commt = true
|
commt = true
|
||||||
case "\n":
|
case "\n":
|
||||||
|
@ -59,10 +59,10 @@ func klexer(s scanner.Scanner, c chan Lex) {
|
||||||
// Reset a comment
|
// Reset a comment
|
||||||
commt = false
|
commt = false
|
||||||
}
|
}
|
||||||
c <- l
|
c <- l
|
||||||
str = ""
|
str = ""
|
||||||
commt = false
|
commt = false
|
||||||
key = true
|
key = true
|
||||||
default:
|
default:
|
||||||
if commt {
|
if commt {
|
||||||
break
|
break
|
||||||
|
|
20
types.go
20
types.go
|
@ -796,7 +796,7 @@ func (rr *RR_TSIG) String() string {
|
||||||
func timeToDate(t uint32) string {
|
func timeToDate(t uint32) string {
|
||||||
utc := time.Now().Unix()
|
utc := time.Now().Unix()
|
||||||
mod := (int64(t) - utc) / Year68
|
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")
|
return ti.Format("20060102150405")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -804,13 +804,13 @@ func timeToDate(t uint32) string {
|
||||||
// string values ("20110403154150") to an integer.
|
// string values ("20110403154150") to an integer.
|
||||||
// Taking into account serial arithmetic (RFC 1982)
|
// Taking into account serial arithmetic (RFC 1982)
|
||||||
func dateToTime(s string) (uint32, error) {
|
func dateToTime(s string) (uint32, error) {
|
||||||
t, e := time.Parse("20060102150405", s)
|
t, e := time.Parse("20060102150405", s)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return 0, e
|
return 0, e
|
||||||
}
|
}
|
||||||
mod := t.Unix() / Year68
|
mod := t.Unix() / Year68
|
||||||
ti := uint32(t.Unix() - (mod * Year68))
|
ti := uint32(t.Unix() - (mod * Year68))
|
||||||
return ti, nil
|
return ti, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Translate the TSIG time signed into a date. There is no
|
// 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
|
// only use the lower 48 bits, TODO(mg), check for 48 bit size
|
||||||
return ""
|
return ""
|
||||||
/*
|
/*
|
||||||
ti := time.Unix(int64(t), 0).Unix()
|
ti := time.Unix(int64(t), 0).Unix()
|
||||||
return ti.Format("20060102150405")
|
return ti.Format("20060102150405")
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
20
zscan.go
20
zscan.go
|
@ -49,10 +49,10 @@ type ParseError struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ParseError) Error() string {
|
func (e *ParseError) Error() string {
|
||||||
va := strconv.Itoa(e.lex.value)
|
va := strconv.Itoa(e.lex.value)
|
||||||
s := e.err + ": `" + e.lex.token + "' (value: " + va + ") at line: " +
|
s := e.err + ": `" + e.lex.token + "' (value: " + va + ") at line: " +
|
||||||
strconv.Itoa(e.lex.line) + " and column: " +
|
strconv.Itoa(e.lex.line) + " and column: " +
|
||||||
strconv.Itoa(e.lex.column)
|
strconv.Itoa(e.lex.column)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ type Lex struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Token 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
|
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
|
// I could save my token here...? l
|
||||||
r, e := setRR(h, c)
|
r, e := setRR(h, c)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
// If e.Lex is nil than we have encounter a unknown RR type
|
// If e.Lex is nil than we have encounter a unknown RR type
|
||||||
// in that case we substitute our current Lex token
|
// in that case we substitute our current Lex token
|
||||||
if e.lex.token == "" && e.lex.value == 0 {
|
if e.lex.token == "" && e.lex.value == 0 {
|
||||||
e.lex = l // Uh, dirty
|
e.lex = l // Uh, dirty
|
||||||
}
|
}
|
||||||
t <- Token{Error: e}
|
t <- Token{Error: e}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ func setRR(h RR_Header, c chan Lex) (RR, *ParseError) {
|
||||||
var r RR
|
var r RR
|
||||||
e := new(ParseError)
|
e := new(ParseError)
|
||||||
switch h.Rrtype {
|
switch h.Rrtype {
|
||||||
// goto Slurpremainder
|
// goto Slurpremainder
|
||||||
case TypeA:
|
case TypeA:
|
||||||
r, e = setA(h, c)
|
r, e = setA(h, c)
|
||||||
if e != nil {
|
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
|
// Get the remaining data until we see a NEWLINE
|
||||||
l = <-c
|
l = <-c
|
||||||
s := ""
|
s := ""
|
||||||
for l.value != _NEWLINE && l.value != _EOF {
|
for l.value != _NEWLINE && l.value != _EOF {
|
||||||
switch l.value {
|
switch l.value {
|
||||||
case _STRING:
|
case _STRING:
|
||||||
|
@ -511,7 +511,7 @@ func setDS(h RR_Header, c chan Lex) (RR, *ParseError) {
|
||||||
}
|
}
|
||||||
// There can be spaces here...
|
// There can be spaces here...
|
||||||
l = <-c
|
l = <-c
|
||||||
s := ""
|
s := ""
|
||||||
for l.value != _NEWLINE && l.value != _EOF {
|
for l.value != _NEWLINE && l.value != _EOF {
|
||||||
switch l.value {
|
switch l.value {
|
||||||
case _STRING:
|
case _STRING:
|
||||||
|
|
Loading…
Reference in New Issue