Quellcode durchsuchen

ciphers: refactor names

Vladislav Yarmak vor 1 Jahr
Ursprung
Commit
169ffa3fca
4 geänderte Dateien mit 17 neuen und 17 gelöschten Zeilen
  1. 11 11
      ciphers/ciphers.go
  2. 1 1
      client/config.go
  3. 4 4
      cmd/dtlspipe/main.go
  4. 1 1
      server/config.go

+ 11 - 11
ciphers/ciphers.go

@@ -9,7 +9,7 @@ import (
 
 type CipherList = []dtls.CipherSuiteID
 
-var FullList = CipherList{
+var FullCipherList = CipherList{
 	dtls.TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256,
 	dtls.TLS_PSK_WITH_AES_128_CCM,
 	dtls.TLS_PSK_WITH_AES_128_CCM_8,
@@ -18,22 +18,22 @@ var FullList = CipherList{
 	dtls.TLS_PSK_WITH_AES_128_CBC_SHA256,
 }
 
-var DefaultList = FullList
-var DefaultListString = ListToString(DefaultList)
-var NameToID map[string]dtls.CipherSuiteID
+var DefaultCipherList = FullCipherList
+var DefaultListString = CipherListToString(DefaultCipherList)
+var CipherNameToID map[string]dtls.CipherSuiteID
 
 func init() {
-	NameToID = make(map[string]dtls.CipherSuiteID)
-	for _, id := range FullList {
-		NameToID[dtls.CipherSuiteName(id)] = id
+	CipherNameToID = make(map[string]dtls.CipherSuiteID)
+	for _, id := range FullCipherList {
+		CipherNameToID[dtls.CipherSuiteName(id)] = id
 	}
 }
 
-func IDToString(id dtls.CipherSuiteID) string {
+func CipherIDToString(id dtls.CipherSuiteID) string {
 	return dtls.CipherSuiteName(id)
 }
 
-func ListToString(lst CipherList) string {
+func CipherListToString(lst CipherList) string {
 	var b strings.Builder
 	var firstPrinted bool
 	for _, id := range lst {
@@ -47,14 +47,14 @@ func ListToString(lst CipherList) string {
 	return b.String()
 }
 
-func StringToList(str string) (CipherList, error) {
+func StringToCipherList(str string) (CipherList, error) {
 	if str == "" {
 		return nil, nil
 	}
 	parts := strings.Split(str, ":")
 	var res CipherList
 	for _, name := range parts {
-		if id, ok := NameToID[name]; ok {
+		if id, ok := CipherNameToID[name]; ok {
 			res = append(res, id)
 		} else {
 			return nil, fmt.Errorf("unknown ciphersuite: %q", name)

+ 1 - 1
client/config.go

@@ -30,7 +30,7 @@ func (cfg *Config) populateDefaults() *Config {
 		cfg.IdleTimeout = 90 * time.Second
 	}
 	if cfg.CipherSuites == nil {
-		cfg.CipherSuites = ciphers.DefaultList
+		cfg.CipherSuites = ciphers.DefaultCipherList
 	}
 	return cfg
 }

+ 4 - 4
cmd/dtlspipe/main.go

@@ -29,11 +29,11 @@ type cipherlistArg struct {
 }
 
 func (l *cipherlistArg) String() string {
-	return ciphers.ListToString(l.Value)
+	return ciphers.CipherListToString(l.Value)
 }
 
 func (l *cipherlistArg) Set(s string) error {
-	parsed, err := ciphers.StringToList(s)
+	parsed, err := ciphers.StringToCipherList(s)
 	if err != nil {
 		return fmt.Errorf("can't parse cipher list: %w", err)
 	}
@@ -163,8 +163,8 @@ func cmdServer(bindAddress, remoteAddress string) int {
 }
 
 func cmdCiphers() int {
-	for _, id := range ciphers.FullList {
-		fmt.Println(ciphers.IDToString(id))
+	for _, id := range ciphers.FullCipherList {
+		fmt.Println(ciphers.CipherIDToString(id))
 	}
 	return 0
 }

+ 1 - 1
server/config.go

@@ -30,7 +30,7 @@ func (cfg *Config) populateDefaults() *Config {
 		cfg.IdleTimeout = 90 * time.Second
 	}
 	if cfg.CipherSuites == nil {
-		cfg.CipherSuites = ciphers.DefaultList
+		cfg.CipherSuites = ciphers.DefaultCipherList
 	}
 	return cfg
 }