You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

unicode.go 622B

1234567891011121314151617181920212223242526272829
  1. package ntlmssp
  2. import (
  3. "bytes"
  4. "encoding/binary"
  5. "errors"
  6. "unicode/utf16"
  7. )
  8. // helper func's for dealing with Windows Unicode (UTF16LE)
  9. func fromUnicode(d []byte) (string, error) {
  10. if len(d)%2 > 0 {
  11. return "", errors.New("Unicode (UTF 16 LE) specified, but uneven data length")
  12. }
  13. s := make([]uint16, len(d)/2)
  14. err := binary.Read(bytes.NewReader(d), binary.LittleEndian, &s)
  15. if err != nil {
  16. return "", err
  17. }
  18. return string(utf16.Decode(s)), nil
  19. }
  20. func toUnicode(s string) []byte {
  21. uints := utf16.Encode([]rune(s))
  22. b := bytes.Buffer{}
  23. binary.Write(&b, binary.LittleEndian, &uints)
  24. return b.Bytes()
  25. }