Put string.go inside DNS package
This commit is contained in:
parent
f06fbca2e2
commit
f274433c46
3
Makefile
3
Makefile
|
@ -14,6 +14,7 @@ GOFILES=\
|
|||
tsig.go\
|
||||
dnssec.go\
|
||||
keygen.go\
|
||||
string.go\
|
||||
|
||||
|
||||
include $(GOROOT)/src/Make.pkg
|
||||
|
@ -21,13 +22,11 @@ include $(GOROOT)/src/Make.pkg
|
|||
all: package
|
||||
gomake -C resolver package
|
||||
gomake -C responder package
|
||||
gomake -C strconv package
|
||||
|
||||
dnstest:
|
||||
gotest
|
||||
gomake -C resolver test
|
||||
gomake -C responder test
|
||||
# gomake -C strconv test
|
||||
|
||||
_examples:
|
||||
gomake -C _examples
|
||||
|
|
|
@ -67,7 +67,7 @@ func (r *RR_DNSKEY) Generate(bits int) (PrivateKey, os.Error) {
|
|||
// of BIND9 (Private-key-format: v1.3). It needs some
|
||||
// info from the key (hashing, keytag), so its a method
|
||||
// of the RR_DNSKEY.
|
||||
func (r *RR_DNSKEY) PrivateKeyToString(p PrivateKey) (s string) {
|
||||
func (r *RR_DNSKEY) PrivateKeyString(p PrivateKey) (s string) {
|
||||
switch t := p.(type) {
|
||||
case *rsa.PrivateKey:
|
||||
algorithm := strconv.Itoa(int(r.Algorithm)) + " (" + alg_str[r.Algorithm] + ")"
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
package dns
|
||||
|
||||
import (
|
||||
"unicode"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
m = 60
|
||||
h = m * m
|
||||
d = 24 * h
|
||||
w = 7 * d
|
||||
)
|
||||
|
||||
// Convert a Ttl to a value. Supported value 'm' for minutes, 'h' for hours
|
||||
// 'w' for week and 'd' for days. Stuff like '1d1d' is legal and return the value of '2d'
|
||||
func StringToSeconds(ttl string) (sec uint32, ok bool) {
|
||||
num := ""
|
||||
for _, k := range ttl {
|
||||
if unicode.IsDigit(k) {
|
||||
num += string(k)
|
||||
} else {
|
||||
i, _ := strconv.Atoi(num)
|
||||
switch k {
|
||||
case 'm':
|
||||
sec += uint32(i) * m
|
||||
case 'h':
|
||||
sec += uint32(i) * h
|
||||
case 'd':
|
||||
sec += uint32(i) * d
|
||||
case 'w':
|
||||
sec += uint32(i) * w
|
||||
default:
|
||||
return
|
||||
}
|
||||
num = ""
|
||||
}
|
||||
}
|
||||
i, _ := strconv.Atoi(num)
|
||||
sec += uint32(i)
|
||||
return
|
||||
}
|
||||
|
||||
func SecondsToString(val uint32) (str string) {
|
||||
mod := val / w
|
||||
if mod > 0 {
|
||||
str += strconv.Itoa(int(mod)) + "w"
|
||||
}
|
||||
val -= mod * w
|
||||
|
||||
mod = val / d
|
||||
if mod > 0 {
|
||||
str += strconv.Itoa(int(mod)) + "d"
|
||||
}
|
||||
val -= mod * d
|
||||
|
||||
mod = val / h
|
||||
if mod > 0 {
|
||||
str += strconv.Itoa(int(mod)) + "h"
|
||||
}
|
||||
val -= mod * h
|
||||
|
||||
mod = val / m
|
||||
if mod > 0 {
|
||||
str += strconv.Itoa(int(mod)) + "m"
|
||||
}
|
||||
val -= mod * m
|
||||
|
||||
if val > 0 {
|
||||
str += strconv.Itoa(int(val))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Read a string and convert it to the correct
|
||||
// Resource Record.
|
||||
func SetString(s string) RR {
|
||||
|
||||
k := new(RR_DNSKEY)
|
||||
return k
|
||||
}
|
Loading…
Reference in New Issue