util.go 772 B

1234567891011121314151617181920212223242526272829
  1. package saml
  2. import (
  3. "crypto/rand"
  4. "time"
  5. dsig "github.com/russellhaering/goxmldsig"
  6. )
  7. // TimeNow is a function that returns the current time. The default
  8. // value is time.Now, but it can be replaced for testing.
  9. var TimeNow = func() time.Time { return time.Now().UTC() }
  10. // Clock is assigned to dsig validation and signing contexts if it is
  11. // not nil, otherwise the default clock is used.
  12. var Clock *dsig.Clock
  13. // RandReader is the io.Reader that produces cryptographically random
  14. // bytes when they are need by the library. The default value is
  15. // rand.Reader, but it can be replaced for testing.
  16. var RandReader = rand.Reader
  17. func randomBytes(n int) []byte {
  18. rv := make([]byte, n)
  19. if _, err := RandReader.Read(rv); err != nil {
  20. panic(err)
  21. }
  22. return rv
  23. }