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
+18k Golang : How to log each HTTP request to your web server?
+9.1k Golang : Gonum standard normal random numbers example
+8.7k Golang : Combine slices but preserve order example
+7.1k Golang : Gorrila mux.Vars() function example
+11.6k SSL : The certificate is not trusted because no issuer chain was provided
+14.6k Golang : Missing Bazaar command
+12.1k Golang : Pagination with go-paginator configuration example
+5.4k Golang : Qt update UI elements with core.QCoreApplication_ProcessEvents
+19.1k Golang : Display list of time zones with GMT
+7.1k Golang : Transform lisp or spinal case to Pascal case example
+13.1k Golang : List objects in AWS S3 bucket