func (s *session) String() string {
	s.mutex.Lock()
	defer s.mutex.Unlock()
	return fmt.Sprintf("Session{type:%s,token:%t,passphrase:%t}",
		s.Type(), s.HasToken(), s.HasPassphrase())
}
String implements the fmt.Stringer interface.
package session
import (
	"errors"
	"fmt"
	"sync"
	"github.com/manifoldco/go-base64"
	"github.com/manifoldco/torus-cli/apitypes"
	"github.com/manifoldco/torus-cli/daemon/crypto/secure"
	"github.com/manifoldco/torus-cli/envelope"
	"github.com/manifoldco/torus-cli/identity"
)
const notLoggedInError = "Please login to perform that command"
type session struct {
	mutex       *sync.Mutex
	sessionType apitypes.SessionType
	identity envelope.Envelope
	auth     envelope.Envelope
	guard      *secure.Guard
	token      *secure.Secret
	passphrase *secure.Secret
}
type Session interface {
	Type() apitypes.SessionType
	Set(apitypes.SessionType, envelope.Envelope, envelope.Envelope, []byte, []byte) error
	SetIdentity(apitypes.SessionType, envelope.Envelope, envelope.Envelope) error
	ID() *identity.ID
	AuthID() *identity.ID
	Token() []byte
	Passphrase() []byte
	MasterKey() (*base64.Value, error)
	HasToken() bool
	HasPassphrase() bool
	Logout() error
	String() string
	Self() *apitypes.Self
}
func NewSession(guard *secure.Guard) Session {
	return &session{
		mutex:       &sync.Mutex{},
		sessionType: apitypes.NotLoggedIn,
		guard:       guard,
	}
}
func (s *session) Type() apitypes.SessionType {
	return s.sessionType
}
func (s *session) ID() *identity.ID {
	s.mutex.Lock()
	defer s.mutex.Unlock()
	if s.identity == nil {
		return nil
	}
	return s.identity.GetID()
}
func (s *session) AuthID() *identity.ID {
	s.mutex.Lock()
	defer s.mutex.Unlock()
	if s.auth == nil {
		return nil
	}
	return s.auth.GetID()
}
func (s *session) Token() []byte {
	s.mutex.Lock()
	defer s.mutex.Unlock()
	return s.token.Buffer()
}
func (s *session) Passphrase() []byte {
	s.mutex.Lock()
	defer s.mutex.Unlock()
	return s.passphrase.Buffer()
}
func (s *session) HasToken() bool {
	return s.token != nil
}
func (s *session) HasPassphrase() bool {
	return s.passphrase != nil
}