github.com/xmidt-org/webpa-common@v1.11.9/secure/key/pair.go (about)

     1  package key
     2  
     3  import (
     4  	"crypto/rsa"
     5  )
     6  
     7  // Pair represents a resolved key pair.  For all Pair instances, the private key is optional,
     8  // while the public key will always be present.
     9  type Pair interface {
    10  	// Purpose returns the configured intended usage of this key pair
    11  	Purpose() Purpose
    12  
    13  	// Public returns the public key associated with this pair.  It will never be nil
    14  	Public() interface{}
    15  
    16  	// HasPrivate tests whether this key Pair has a private key
    17  	HasPrivate() bool
    18  
    19  	// Private returns the optional private key associated with this Pair.  If there
    20  	// is no private key, this method returns nil.
    21  	Private() interface{}
    22  }
    23  
    24  // rsaPair is an RSA key Pair implementation
    25  type rsaPair struct {
    26  	purpose Purpose
    27  	public  interface{}
    28  	private *rsa.PrivateKey
    29  }
    30  
    31  func (rp *rsaPair) Purpose() Purpose {
    32  	return rp.purpose
    33  }
    34  
    35  func (rp *rsaPair) Public() interface{} {
    36  	return rp.public
    37  }
    38  
    39  func (rp *rsaPair) HasPrivate() bool {
    40  	return rp.private != nil
    41  }
    42  
    43  func (rp *rsaPair) Private() interface{} {
    44  	if rp.private != nil {
    45  		return rp.private
    46  	}
    47  
    48  	return nil
    49  }