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