OSDN Git Service

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