...

Source file src/github.com/digitorus/timestamp/borrowed.go

Documentation: github.com/digitorus/timestamp

     1  package timestamp
     2  
     3  import (
     4  	"crypto"
     5  	"encoding/asn1"
     6  )
     7  
     8  // TODO(vanbroup): taken from "golang.org/x/crypto/ocsp"
     9  // use directly from crypto/x509 when exported as suggested below.
    10  
    11  var hashOIDs = map[crypto.Hash]asn1.ObjectIdentifier{
    12  	crypto.SHA1:   asn1.ObjectIdentifier([]int{1, 3, 14, 3, 2, 26}),
    13  	crypto.SHA256: asn1.ObjectIdentifier([]int{2, 16, 840, 1, 101, 3, 4, 2, 1}),
    14  	crypto.SHA384: asn1.ObjectIdentifier([]int{2, 16, 840, 1, 101, 3, 4, 2, 2}),
    15  	crypto.SHA512: asn1.ObjectIdentifier([]int{2, 16, 840, 1, 101, 3, 4, 2, 3}),
    16  }
    17  
    18  // TODO(rlb): This is not taken from crypto/x509, but it's of the same general form.
    19  func getHashAlgorithmFromOID(target asn1.ObjectIdentifier) crypto.Hash {
    20  	for hash, oid := range hashOIDs {
    21  		if oid.Equal(target) {
    22  			return hash
    23  		}
    24  	}
    25  	return crypto.Hash(0)
    26  }
    27  
    28  func getOIDFromHashAlgorithm(target crypto.Hash) asn1.ObjectIdentifier {
    29  	for hash, oid := range hashOIDs {
    30  		if hash == target {
    31  			return oid
    32  		}
    33  	}
    34  	return nil
    35  }
    36  
    37  // TODO(vanbroup): taken from golang.org/x/crypto/x509
    38  // asn1BitLength returns the bit-length of bitString by considering the
    39  // most-significant bit in a byte to be the "first" bit. This convention
    40  // matches ASN.1, but differs from almost everything else.
    41  func asn1BitLength(bitString []byte) int {
    42  	bitLen := len(bitString) * 8
    43  
    44  	for i := range bitString {
    45  		b := bitString[len(bitString)-i-1]
    46  
    47  		for bit := uint(0); bit < 8; bit++ {
    48  			if (b>>bit)&1 == 1 {
    49  				return bitLen
    50  			}
    51  			bitLen--
    52  		}
    53  	}
    54  
    55  	return 0
    56  }
    57  

View as plain text