]> ruderich.org/simon Gitweb - nsscash/nsscash.git/blobdiff - passwd.go
nsscash: improve comments
[nsscash/nsscash.git] / passwd.go
index c07e9c73914d378d8964756994542f92eeefb3b1..07a62d8b8667d510d395fb8b5bd4a8a0c2c55570 100644 (file)
--- a/passwd.go
+++ b/passwd.go
@@ -44,7 +44,7 @@ type Passwd struct {
 }
 
 // ParsePasswds parses a file in the format of /etc/passwd and returns all
-// entries as Passwd structs.
+// entries as slice of Passwd structs.
 func ParsePasswds(r io.Reader) ([]Passwd, error) {
        var res []Passwd
 
@@ -134,12 +134,7 @@ func SerializePasswd(p Passwd) []byte {
        res.Write(data.Bytes())
        // We must pad each entry so that all uint64 at the beginning of the
        // struct are 8 byte aligned
-       l := res.Len()
-       if l%8 != 0 {
-               for i := 0; i < 8-l%8; i++ {
-                       res.Write([]byte{'0'})
-               }
-       }
+       alignBufferTo(&res, 8)
 
        return res.Bytes()
 }
@@ -191,7 +186,8 @@ func SerializePasswds(w io.Writer, pws []Passwd) error {
        }
 
        // Sanity check
-       if indexOrig.Len() != indexId.Len() ||
+       if len(pws)*8 != indexOrig.Len() ||
+               indexOrig.Len() != indexId.Len() ||
                indexId.Len() != indexName.Len() {
                return fmt.Errorf("indexes have inconsistent length")
        }