...

Source file src/github.com/sassoftware/relic/token/p11token/byteorder.go

Documentation: github.com/sassoftware/relic/token/p11token

     1  //
     2  // Copyright (c) SAS Institute Inc.
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //     http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  //
    16  
    17  package p11token
    18  
    19  import (
    20  	"encoding/binary"
    21  	"unsafe"
    22  )
    23  
    24  var (
    25  	nativeOrder binary.ByteOrder
    26  	ulongSize   int
    27  )
    28  
    29  func init() {
    30  	var i uint32 = 0x1
    31  	bs := (*[4]byte)(unsafe.Pointer(&i))
    32  	if bs[0] == 0 {
    33  		nativeOrder = binary.BigEndian
    34  	} else {
    35  		nativeOrder = binary.LittleEndian
    36  	}
    37  	var j uint
    38  	ulongSize = int(unsafe.Sizeof(j))
    39  }
    40  
    41  func putUlong(buf []byte, v uint) {
    42  	switch ulongSize {
    43  	case 4:
    44  		nativeOrder.PutUint32(buf, uint32(v))
    45  	case 8:
    46  		nativeOrder.PutUint64(buf, uint64(v))
    47  	default:
    48  		panic("can't determine native integer size")
    49  	}
    50  }
    51  

View as plain text