Jonathan Turner 8 anni fa
parent
commit
fb38b5112d
2 ha cambiato i file con 12 aggiunte e 8 eliminazioni
  1. 6 3
      keytab/keytab.go
  2. 6 5
      types/HostAddress.go

+ 6 - 3
keytab/keytab.go

@@ -108,7 +108,8 @@ func Load(ktPath string) (kt Keytab, err error) {
 	return Parse(k)
 }
 
-func (kt Keytab) marshal() ([]byte, error) {
+// Marshal keytab into byte slice
+func (kt Keytab) Marshal() ([]byte, error) {
 	b := []byte{keytabFirstByte, kt.Version}
 	for _, e := range kt.Entries {
 		eb, err := e.marshal(int(kt.Version))
@@ -120,8 +121,10 @@ func (kt Keytab) marshal() ([]byte, error) {
 	return b, nil
 }
 
+// Write the keytab bytes to io.Writer.
+// Returns the number of bytes written
 func (kt Keytab) Write(w io.Writer) (int, error) {
-	b, err := kt.marshal()
+	b, err := kt.Marshal()
 	if err != nil {
 		return 0, fmt.Errorf("error marshaling keytab: %v", err)
 	}
@@ -239,7 +242,7 @@ func (e entry) marshal(v int) ([]byte, error) {
 }
 
 // Parse the Keytab bytes of a principal into a Keytab entry's principal.
-func parsePrincipal(b []byte, p *int, kt *Keytab, ke *entry, e *binary.ByteOrder) (err error) {
+func parsePrincipal(b []byte, p *int, kt *Keytab, ke *entry, e *binary.ByteOrder) error {
 	ke.Principal.NumComponents = readInt16(b, p, e)
 	if kt.Version == 1 {
 		//In version 1 the number of components includes the realm. Minus 1 to make consistent with version 2

+ 6 - 5
types/HostAddress.go

@@ -120,6 +120,7 @@ func LocalHostAddresses() (ha HostAddresses, err error) {
 	return ha, nil
 }
 
+// HostAddressFromNetIPs returns a HostAddresses type from a slice of net.IP
 func HostAddressesFromNetIPs(ips []net.IP) (ha HostAddresses) {
 	for _, ip := range ips {
 		ha = append(ha, HostAddressFromNetIP(ip))
@@ -127,6 +128,7 @@ func HostAddressesFromNetIPs(ips []net.IP) (ha HostAddresses) {
 	return ha
 }
 
+// HostAddressFromNetIP returns a HostAddress type from a net.IP
 func HostAddressFromNetIP(ip net.IP) HostAddress {
 	if ip.To4() != nil {
 		//Is IPv4
@@ -134,11 +136,10 @@ func HostAddressFromNetIP(ip net.IP) HostAddress {
 			AddrType: addrtype.IPv4,
 			Address:  ip.To4(),
 		}
-	} else {
-		return HostAddress{
-			AddrType: addrtype.IPv6,
-			Address:  ip.To16(),
-		}
+	}
+	return HostAddress{
+		AddrType: addrtype.IPv6,
+		Address:  ip.To16(),
 	}
 }