OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / tendermint / go-crypto / privkeyinner_wrapper.go
1 // Generated by: main
2 // TypeWriter: wrapper
3 // Directive: +gen on PrivKeyInner
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 PrivKey struct {
16         PrivKeyInner "json:\"unwrap\""
17 }
18
19 var PrivKeyMapper = data.NewMapper(PrivKey{})
20
21 func (h PrivKey) MarshalJSON() ([]byte, error) {
22         return PrivKeyMapper.ToJSON(h.PrivKeyInner)
23 }
24
25 func (h *PrivKey) UnmarshalJSON(data []byte) (err error) {
26         parsed, err := PrivKeyMapper.FromJSON(data)
27         if err == nil && parsed != nil {
28                 h.PrivKeyInner = parsed.(PrivKeyInner)
29         }
30         return err
31 }
32
33 // Unwrap recovers the concrete interface safely (regardless of levels of embeds)
34 func (h PrivKey) Unwrap() PrivKeyInner {
35         hi := h.PrivKeyInner
36         for wrap, ok := hi.(PrivKey); ok; wrap, ok = hi.(PrivKey) {
37                 hi = wrap.PrivKeyInner
38         }
39         return hi
40 }
41
42 func (h PrivKey) Empty() bool {
43         return h.PrivKeyInner == nil
44 }
45
46 /*** below are bindings for each implementation ***/
47
48 func init() {
49         PrivKeyMapper.RegisterImplementation(PrivKeyEd25519{}, "ed25519", 0x1)
50 }
51
52 func (hi PrivKeyEd25519) Wrap() PrivKey {
53         return PrivKey{hi}
54 }
55
56 func init() {
57         PrivKeyMapper.RegisterImplementation(PrivKeySecp256k1{}, "secp256k1", 0x2)
58 }
59
60 func (hi PrivKeySecp256k1) Wrap() PrivKey {
61         return PrivKey{hi}
62 }