Remove support for legacy CSV files
This commit is contained in:
parent
3d67c81697
commit
f20da6b611
|
@ -104,7 +104,7 @@
|
|||
branch = "master"
|
||||
name = "github.com/jedisct1/go-dnsstamps"
|
||||
packages = ["."]
|
||||
revision = "d8908ceb62ed5ff9fe230d14cdde7727b90737e6"
|
||||
revision = "1e4999280f861b465e03e21e4f84d838f2f02b38"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/csv"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
@ -24,8 +23,7 @@ import (
|
|||
type SourceFormat int
|
||||
|
||||
const (
|
||||
SourceFormatV1 = iota
|
||||
SourceFormatV2
|
||||
SourceFormatV2 = iota
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -129,9 +127,7 @@ type URLToPrefetch struct {
|
|||
func NewSource(xTransport *XTransport, urls []string, minisignKeyStr string, cacheFile string, formatStr string, refreshDelay time.Duration) (Source, []URLToPrefetch, error) {
|
||||
_ = refreshDelay
|
||||
source := Source{urls: urls}
|
||||
if formatStr == "v1" {
|
||||
source.format = SourceFormatV1
|
||||
} else if formatStr == "v2" {
|
||||
if formatStr == "v2" {
|
||||
source.format = SourceFormatV2
|
||||
} else {
|
||||
return source, []URLToPrefetch{}, fmt.Errorf("Unsupported source format: [%s]", formatStr)
|
||||
|
@ -210,58 +206,13 @@ func NewSource(xTransport *XTransport, urls []string, minisignKeyStr string, cac
|
|||
}
|
||||
|
||||
func (source *Source) Parse(prefix string) ([]RegisteredServer, error) {
|
||||
if source.format == SourceFormatV1 {
|
||||
return source.parseV1(prefix)
|
||||
} else if source.format == SourceFormatV2 {
|
||||
if source.format == SourceFormatV2 {
|
||||
return source.parseV2(prefix)
|
||||
}
|
||||
dlog.Fatal("Unexpected source format")
|
||||
return []RegisteredServer{}, nil
|
||||
}
|
||||
|
||||
func (source *Source) parseV1(prefix string) ([]RegisteredServer, error) {
|
||||
var registeredServers []RegisteredServer
|
||||
|
||||
csvReader := csv.NewReader(strings.NewReader(source.in))
|
||||
records, err := csvReader.ReadAll()
|
||||
if err != nil {
|
||||
return registeredServers, nil
|
||||
}
|
||||
for lineNo, record := range records {
|
||||
if len(record) == 0 {
|
||||
continue
|
||||
}
|
||||
if len(record) < 14 {
|
||||
return registeredServers, fmt.Errorf("Parse error at line %d", 1+lineNo)
|
||||
}
|
||||
if lineNo == 0 {
|
||||
continue
|
||||
}
|
||||
name := prefix + record[0]
|
||||
description := record[2]
|
||||
serverAddrStr := record[10]
|
||||
providerName := record[11]
|
||||
serverPkStr := record[12]
|
||||
props := stamps.ServerInformalProperties(0)
|
||||
if strings.EqualFold(record[7], "yes") {
|
||||
props |= stamps.ServerInformalPropertyDNSSEC
|
||||
}
|
||||
if strings.EqualFold(record[8], "yes") {
|
||||
props |= stamps.ServerInformalPropertyNoLog
|
||||
}
|
||||
stamp, err := stamps.NewDNSCryptServerStampFromLegacy(serverAddrStr, serverPkStr, providerName, props)
|
||||
if err != nil {
|
||||
return registeredServers, err
|
||||
}
|
||||
registeredServer := RegisteredServer{
|
||||
name: name, stamp: stamp, description: description,
|
||||
}
|
||||
dlog.Debugf("Registered [%s] with stamp [%s]", name, stamp.String())
|
||||
registeredServers = append(registeredServers, registeredServer)
|
||||
}
|
||||
return registeredServers, nil
|
||||
}
|
||||
|
||||
func (source *Source) parseV2(prefix string) ([]RegisteredServer, error) {
|
||||
var registeredServers []RegisteredServer
|
||||
in := string(source.in)
|
||||
|
|
|
@ -1,18 +1,9 @@
|
|||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/crypto"
|
||||
packages = [
|
||||
"ed25519",
|
||||
"ed25519/internal/edwards25519"
|
||||
]
|
||||
revision = "d6449816ce06963d9d136eee5a56fca5b0616e7e"
|
||||
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "5046e265393bd5e54f570ce29ae8bc6fa3f30ef5110e922996540400f287c64a"
|
||||
inputs-digest = "ab4fef131ee828e96ba67d31a7d690bd5f2f42040c6766b1b12fe856f87e0ff7"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
|
|
|
@ -9,8 +9,6 @@ import (
|
|||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/crypto/ed25519"
|
||||
)
|
||||
|
||||
const DefaultPort = 443
|
||||
|
@ -60,7 +58,7 @@ func NewDNSCryptServerStampFromLegacy(serverAddrStr string, serverPkStr string,
|
|||
serverAddrStr = fmt.Sprintf("%s:%d", serverAddrStr, DefaultPort)
|
||||
}
|
||||
serverPk, err := hex.DecodeString(strings.Replace(serverPkStr, ":", "", -1))
|
||||
if err != nil || len(serverPk) != ed25519.PublicKeySize {
|
||||
if err != nil || len(serverPk) != 32 {
|
||||
return ServerStamp{}, fmt.Errorf("Unsupported public key: [%s]", serverPkStr)
|
||||
}
|
||||
return ServerStamp{
|
||||
|
|
Loading…
Reference in New Issue