File: ldap.go

package info (click to toggle)
golang-github-go-crypt-x 0.4.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 640 kB
  • sloc: asm: 4,824; makefile: 2
file content (31 lines) | stat: -rw-r--r-- 452 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package ldap

import (
	"bytes"
	"hash"
)

// Key returns the RFC2307 key for the provided password and optional salt. Generally this is encoded with base64.
func Key(hashFunc func() hash.Hash, password, salt []byte) []byte {
	s := len(salt) != 0

	digest := hashFunc()

	digest.Write(password)

	if s {
		digest.Write(salt)
	}

	buf := &bytes.Buffer{}

	buf.Write(digest.Sum(nil))

	digest.Reset()

	if s {
		buf.Write(salt)
	}

	return buf.Bytes()
}