github.com/braveheart12/just@v0.8.7/core/delegationtoken/base.go (about)

     1  /*
     2   *    Copyright 2019 Insolar Technologies
     3   *
     4   *    Licensed under the Apache License, Version 2.0 (the "License");
     5   *    you may not use this file except in compliance with the License.
     6   *    You may obtain a copy of the License at
     7   *
     8   *        http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   *    Unless required by applicable law or agreed to in writing, software
    11   *    distributed under the License is distributed on an "AS IS" BASIS,
    12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   *    See the License for the specific language governing permissions and
    14   *    limitations under the License.
    15   */
    16  
    17  // Package delegationtoken is about an authorization token that allows a node to perform
    18  // actions it can not normally perform during this pulse
    19  package delegationtoken
    20  
    21  import (
    22  	"encoding/gob"
    23  
    24  	"github.com/insolar/insolar/core"
    25  	"github.com/pkg/errors"
    26  )
    27  
    28  type PendingExecutionToken struct {
    29  	Signature []byte
    30  }
    31  
    32  func (t *PendingExecutionToken) Type() core.DelegationTokenType {
    33  	return core.DTTypePendingExecution
    34  }
    35  
    36  func (t *PendingExecutionToken) Verify(parcel core.Parcel) (bool, error) {
    37  	switch mt := parcel.Message().Type(); mt {
    38  
    39  	//TODO: stab should start verification
    40  	case core.TypeCallMethod:
    41  		return false, nil
    42  	default:
    43  		return false, errors.Errorf("Message of type %s can't be delegated with %s token", t.Type(), mt)
    44  	}
    45  }
    46  
    47  // GetObjectRedirectToken is a redirect token for the GetObject method
    48  type GetObjectRedirectToken struct {
    49  	Signature []byte
    50  }
    51  
    52  // Type implementation of Token interface.
    53  func (t *GetObjectRedirectToken) Type() core.DelegationTokenType {
    54  	return core.DTTypeGetObjectRedirect
    55  }
    56  
    57  // Verify implementation of Token interface.
    58  func (t *GetObjectRedirectToken) Verify(parcel core.Parcel) (bool, error) {
    59  	panic("implement me")
    60  }
    61  
    62  // GetChildrenRedirectToken is a redirect token for the GetObject method
    63  type GetChildrenRedirectToken struct {
    64  	Signature []byte
    65  }
    66  
    67  // Type implementation of Token interface.
    68  func (t *GetChildrenRedirectToken) Type() core.DelegationTokenType {
    69  	return core.DTTypeGetChildrenRedirect
    70  }
    71  
    72  // Verify implementation of Token interface.
    73  func (t *GetChildrenRedirectToken) Verify(parcel core.Parcel) (bool, error) {
    74  	panic("implement me")
    75  }
    76  
    77  // GetCodeRedirectToken is a redirect token for the GetObject method
    78  type GetCodeRedirectToken struct {
    79  	Signature []byte
    80  }
    81  
    82  // Type implementation of Token interface.
    83  func (t *GetCodeRedirectToken) Type() core.DelegationTokenType {
    84  	return core.DTTypeGetCodeRedirect
    85  }
    86  
    87  // Verify implementation of Token interface.
    88  func (t *GetCodeRedirectToken) Verify(parcel core.Parcel) (bool, error) {
    89  	panic("implement me")
    90  }
    91  
    92  func init() {
    93  	gob.Register(&PendingExecutionToken{})
    94  	gob.Register(&GetObjectRedirectToken{})
    95  	gob.Register(&GetChildrenRedirectToken{})
    96  	gob.Register(&GetCodeRedirectToken{})
    97  }