Golang crypto/subtle.ConstantTimeCopy() function example
package crypto/subtle
ConstantTimeCopy copies the contents of y(3rd param) into x(2nd param) iff v == 1. If v == 0, x is left unchanged. Its behavior is undefined if v(1st param) takes any other value.
Golang crypto/subtle.ConstantTimeCopy() function usage example
package main
import (
"crypto/subtle"
"fmt"
)
func main() {
y := []byte("Hello")
x := make([]byte, len(y))
subtle.ConstantTimeCopy(0, x, y) // v = 0
fmt.Printf("%s\n", x) // will NOT copy y to x
subtle.ConstantTimeCopy(1, x, y) // v = 1
fmt.Printf("%s\n", x) // will copy y to x
}
Output :
go run constanttimecopy.go
__
Hello
Reference :
Advertisement
Something interesting
Tutorials
+24k Golang : Call function from another package
+14.6k Golang : Send email with attachment(RFC2822) using Gmail API example
+46.2k Golang : Read tab delimited file with encoding/csv package
+10.1k Golang : Check a web page existence with HEAD request example
+12.3k Golang : Validate email address
+16.9k Golang : Set up source IP address before making HTTP request
+21.1k Golang : Sort and reverse sort a slice of strings
+9.3k Golang : Timeout example
+5.6k Unix/Linux : How to find out the hard disk size?
+30.5k Get client IP Address in Go
+21.6k Golang : Encrypt and decrypt data with TripleDES
+18.9k Golang : Read input from console line