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.3 KiB

  1. // Generated by: main
  2. // TypeWriter: wrapper
  3. // Directive: +gen on PubKeyInner
  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 PubKey struct {
  12. PubKeyInner "json:\"unwrap\""
  13. }
  14. var PubKeyMapper = data.NewMapper(PubKey{})
  15. func (h PubKey) MarshalJSON() ([]byte, error) {
  16. return PubKeyMapper.ToJSON(h.PubKeyInner)
  17. }
  18. func (h *PubKey) UnmarshalJSON(data []byte) (err error) {
  19. parsed, err := PubKeyMapper.FromJSON(data)
  20. if err == nil && parsed != nil {
  21. h.PubKeyInner = parsed.(PubKeyInner)
  22. }
  23. return err
  24. }
  25. // Unwrap recovers the concrete interface safely (regardless of levels of embeds)
  26. func (h PubKey) Unwrap() PubKeyInner {
  27. hi := h.PubKeyInner
  28. for wrap, ok := hi.(PubKey); ok; wrap, ok = hi.(PubKey) {
  29. hi = wrap.PubKeyInner
  30. }
  31. return hi
  32. }
  33. func (h PubKey) Empty() bool {
  34. return h.PubKeyInner == nil
  35. }
  36. /*** below are bindings for each implementation ***/
  37. func init() {
  38. PubKeyMapper.RegisterImplementation(PubKeyEd25519{}, "ed25519", 0x1)
  39. }
  40. func (hi PubKeyEd25519) Wrap() PubKey {
  41. return PubKey{hi}
  42. }
  43. func init() {
  44. PubKeyMapper.RegisterImplementation(PubKeySecp256k1{}, "secp256k1", 0x2)
  45. }
  46. func (hi PubKeySecp256k1) Wrap() PubKey {
  47. return PubKey{hi}
  48. }