Use bufio.Reader in private key reading

This commit is contained in:
Miek Gieben 2011-03-23 16:10:15 +01:00
parent 8ebf0c9a5b
commit 3af023bda9
6 changed files with 9 additions and 30 deletions

1
TODO
View File

@ -10,7 +10,6 @@ o compression (only ownernames?)
o Key2DS, also for offline keys -- need to parse them ofcourse
o Closing of tcp connections?
o Tsig will probably become an interface which has all configuration
stuff, but this will come later. Config which has Tsig function

View File

@ -342,7 +342,7 @@ func (s *RR_RRSIG) Verify(k *RR_DNSKEY, rrset RRset) bool {
}
// Use RFC1982 to calculate if a signature period is valid.
func (s *RR_RRSIG) PeriodOK() bool {
func (s *RR_RRSIG) ValidityPeriod() bool {
utc := time.UTC().Seconds()
modi := (int64(s.Inception) - utc) / Year68
mode := (int64(s.Expiration) - utc) / Year68

View File

@ -5,7 +5,6 @@ import (
"big"
"fmt"
"bufio"
"strings"
"strconv"
"crypto/rsa"
"crypto/rand"
@ -89,9 +88,8 @@ func (r *RR_DNSKEY) PrivateKeyString(p PrivateKey) (s string) {
}
// Read a private key (file) string and create a public key. Return the private key.
func (k *RR_DNSKEY) PrivateKeySetString(s string) (PrivateKey, os.Error) {
func (k *RR_DNSKEY) ReadPrivateKey(r bufio.Reader) (PrivateKey, os.Error) {
p := new(rsa.PrivateKey)
r := bufio.NewReader(strings.NewReader(s))
var left, right string
line, _ := r.ReadBytes('\n')
// Do we care about the order of things? TODO(mg)

View File

@ -45,7 +45,7 @@ Publish: 20101221142359
Activate: 20101221142359`
k := new(RR_DNSKEY)
p, _ := k.PrivateKeySetString(a)
p, _ := k.ReadPrivateKey(strings.NewReader(a))
p = p
}

View File

@ -48,15 +48,10 @@ func HandleTCP(l *net.TCPListener, f func(*Conn, *Msg)) os.Error {
d.Addr = c.RemoteAddr()
d.Port = d.TCP.RemoteAddr().(*net.TCPAddr).Port
m := d.NewBuffer()
n, e := d.Read(m)
if e != nil {
continue
}
m = m[:n]
msg := new(Msg)
if !msg.Unpack(m) {
err := d.ReadMsg(msg)
if err != nil {
// Logging??
continue
}

19
xfr.go
View File

@ -44,18 +44,11 @@ func (d *Conn) axfrRead(q *Msg, m chan Xfr) {
first := true
in := new(Msg)
for {
inb := d.NewBuffer()
n, err := d.Read(inb)
err := d.ReadMsg(in)
if err != nil {
m <- Xfr{true, nil, err}
return
}
inb = inb[:n]
if !in.Unpack(inb) {
m <- Xfr{true, nil, &Error{Error: "Failed to unpack"}}
return
}
if in.Id != q.Id {
m <- Xfr{true, nil, &Error{Error: "Id mismatch"}}
return
@ -135,18 +128,12 @@ func (d *Conn) ixfrRead(q *Msg, m chan Xfr) {
first := true
in := new(Msg)
for {
inb := d.NewBuffer()
n, err := d.Read(inb)
err := d.ReadMsg(in)
if err != nil {
m <- Xfr{true, nil, err}
return
}
inb = inb[:n]
if !in.Unpack(inb) {
m <- Xfr{true, nil, &Error{Error: "Failed to unpack"}}
return
}
if in.Id != q.Id {
m <- Xfr{true, nil, &Error{Error: "Id mismatch"}}
return