-
Notifications
You must be signed in to change notification settings - Fork 546
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7f985a
commit 641d096
Showing
10 changed files
with
383 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package nameservers | ||
|
||
import ( | ||
"net/netip" | ||
"strings" | ||
) | ||
|
||
func Split(rawNameServers string) *[]netip.Addr { | ||
nameServers := make([]netip.Addr, 0) | ||
if rawNameServers == "" { | ||
return &nameServers | ||
} | ||
nameServerArrays := strings.Split(rawNameServers, " ") | ||
for _, nameServer := range nameServerArrays { | ||
nameServerSubArrays := strings.Split(nameServer, ",") | ||
if len(nameServerSubArrays) > 1 { | ||
tmpNameServers := make([]netip.Addr, len(nameServerSubArrays)) | ||
for i, e := range nameServerSubArrays { | ||
tmpNameServers[i], _ = netip.ParseAddr(e) | ||
} | ||
nameServers = append(nameServers, tmpNameServers...) | ||
} else { | ||
tmpNameServer, _ := netip.ParseAddr(nameServer) | ||
nameServers = append(nameServers, tmpNameServer) | ||
} | ||
} | ||
return &nameServers | ||
} | ||
|
||
func String(nameServers *[]netip.Addr) string { | ||
if nameServers != nil { | ||
var rawNameServers string | ||
for _, nameServer := range *nameServers { | ||
rawNameServers += " " + nameServer.String() | ||
} | ||
if rawNameServers != "" { | ||
return rawNameServers[1:] | ||
} | ||
} | ||
return "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package sshkeys | ||
|
||
import ( | ||
"crypto" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
var regexMultipleSpaces = regexp.MustCompile(`\s+`) | ||
|
||
func Split(rawKeys string) *[]crypto.PublicKey { | ||
tmpKeys := strings.Split(rawKeys, "\n") | ||
keys := make([]crypto.PublicKey, len(tmpKeys)) | ||
for i, e := range tmpKeys { | ||
keys[i] = crypto.PublicKey(e) | ||
} | ||
return &keys | ||
} | ||
|
||
func String(keys *[]crypto.PublicKey) string { | ||
if keys != nil { | ||
var rawKeys string | ||
for _, key := range *keys { | ||
rawKeys += "\n" + key.(string) | ||
} | ||
if rawKeys != "" { | ||
return rawKeys[1:] | ||
} | ||
} | ||
return "" | ||
} | ||
|
||
func Trim(rawKeys string) string { | ||
return regexMultipleSpaces.ReplaceAllString(strings.TrimSpace(rawKeys), " ") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.