ducky/devices

Paddy 2015-11-12

0:b6494e1a499e Go to Latest

ducky/devices/vendor/code.google.com/p/go-uuid/uuid/hash.go

Initial attempt. Create the basic types (Device, DeviceType, DeviceChange) that we'll be using in the service. Also, create our Storer interface, and the helper methods to store, retrieve, and update information in the datastore. Also, we're using Godep, so check in our Godeps folder and the vendor folder. Note that this only works on Go 1.5 and later, with the GO15VENDOREXPERIMENT environment variable set to 1.

History
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/vendor/code.google.com/p/go-uuid/uuid/hash.go	Thu Nov 12 20:33:26 2015 -0800
     1.3 @@ -0,0 +1,53 @@
     1.4 +// Copyright 2011 Google Inc.  All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style
     1.6 +// license that can be found in the LICENSE file.
     1.7 +
     1.8 +package uuid
     1.9 +
    1.10 +import (
    1.11 +	"crypto/md5"
    1.12 +	"crypto/sha1"
    1.13 +	"hash"
    1.14 +)
    1.15 +
    1.16 +// Well known Name Space IDs and UUIDs
    1.17 +var (
    1.18 +	NameSpace_DNS  = Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
    1.19 +	NameSpace_URL  = Parse("6ba7b811-9dad-11d1-80b4-00c04fd430c8")
    1.20 +	NameSpace_OID  = Parse("6ba7b812-9dad-11d1-80b4-00c04fd430c8")
    1.21 +	NameSpace_X500 = Parse("6ba7b814-9dad-11d1-80b4-00c04fd430c8")
    1.22 +	NIL            = Parse("00000000-0000-0000-0000-000000000000")
    1.23 +)
    1.24 +
    1.25 +// NewHash returns a new UUID dervied from the hash of space concatenated with
    1.26 +// data generated by h.  The hash should be at least 16 byte in length.  The
    1.27 +// first 16 bytes of the hash are used to form the UUID.  The version of the
    1.28 +// UUID will be the lower 4 bits of version.  NewHash is used to implement
    1.29 +// NewMD5 and NewSHA1.
    1.30 +func NewHash(h hash.Hash, space UUID, data []byte, version int) UUID {
    1.31 +	h.Reset()
    1.32 +	h.Write(space)
    1.33 +	h.Write([]byte(data))
    1.34 +	s := h.Sum(nil)
    1.35 +	uuid := make([]byte, 16)
    1.36 +	copy(uuid, s)
    1.37 +	uuid[6] = (uuid[6] & 0x0f) | uint8((version&0xf)<<4)
    1.38 +	uuid[8] = (uuid[8] & 0x3f) | 0x80 // RFC 4122 variant
    1.39 +	return uuid
    1.40 +}
    1.41 +
    1.42 +// NewMD5 returns a new MD5 (Version 3) UUID based on the
    1.43 +// supplied name space and data.
    1.44 +//
    1.45 +//  NewHash(md5.New(), space, data, 3)
    1.46 +func NewMD5(space UUID, data []byte) UUID {
    1.47 +	return NewHash(md5.New(), space, data, 3)
    1.48 +}
    1.49 +
    1.50 +// NewSHA1 returns a new SHA1 (Version 5) UUID based on the
    1.51 +// supplied name space and data.
    1.52 +//
    1.53 +//  NewHash(sha1.New(), space, data, 5)
    1.54 +func NewSHA1(space UUID, data []byte) UUID {
    1.55 +	return NewHash(sha1.New(), space, data, 5)
    1.56 +}