You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.4 KiB

  1. // Generated by: main
  2. // TypeWriter: wrapper
  3. // Directive: +gen on SignatureInner
  4. package crypto
  5. import (
  6. "github.com/tendermint/go-wire/data"
  7. )
  8. // Auto-generated adapters for happily unmarshaling interfaces
  9. // Apache License 2.0
  10. // Copyright (c) 2017 Ethan Frey (ethan.frey@tendermint.com)
  11. type Signature struct {
  12. SignatureInner "json:\"unwrap\""
  13. }
  14. var SignatureMapper = data.NewMapper(Signature{})
  15. func (h Signature) MarshalJSON() ([]byte, error) {
  16. return SignatureMapper.ToJSON(h.SignatureInner)
  17. }
  18. func (h *Signature) UnmarshalJSON(data []byte) (err error) {
  19. parsed, err := SignatureMapper.FromJSON(data)
  20. if err == nil && parsed != nil {
  21. h.SignatureInner = parsed.(SignatureInner)
  22. }
  23. return err
  24. }
  25. // Unwrap recovers the concrete interface safely (regardless of levels of embeds)
  26. func (h Signature) Unwrap() SignatureInner {
  27. hi := h.SignatureInner
  28. for wrap, ok := hi.(Signature); ok; wrap, ok = hi.(Signature) {
  29. hi = wrap.SignatureInner
  30. }
  31. return hi
  32. }
  33. func (h Signature) Empty() bool {
  34. return h.SignatureInner == nil
  35. }
  36. /*** below are bindings for each implementation ***/
  37. func init() {
  38. SignatureMapper.RegisterImplementation(SignatureEd25519{}, "ed25519", 0x1)
  39. }
  40. func (hi SignatureEd25519) Wrap() Signature {
  41. return Signature{hi}
  42. }
  43. func init() {
  44. SignatureMapper.RegisterImplementation(SignatureSecp256k1{}, "secp256k1", 0x2)
  45. }
  46. func (hi SignatureSecp256k1) Wrap() Signature {
  47. return Signature{hi}
  48. }