github.com/olivere/camlistore@v0.0.0-20140121221811-1b7ac2da0199/third_party/code.google.com/p/go.crypto/openpgp/packet/config.go (about)

     1  // Copyright 2012 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package packet
     6  
     7  import (
     8  	"crypto"
     9  	"crypto/rand"
    10  	"io"
    11  	"time"
    12  )
    13  
    14  // Config collects a number of parameters along with sensible defaults.
    15  
    16  // A nil *Config is valid and produces all default values.
    17  type Config struct {
    18  	// Rand provides the source of entropy.
    19  	// If nil, the crypto/rand Reader is used.
    20  	Rand io.Reader
    21  	// DefaultHash is the default hash function to be used.
    22  	// If zero, SHA-256 is used.
    23  	DefaultHash crypto.Hash
    24  	// DefaultCipher is the cipher to be used.
    25  	// If zero, AES-128 is used.
    26  	DefaultCipher CipherFunction
    27  	// Time returns the current time as the number of seconds since the
    28  	// epoch. If Time is nil, time.Now is used.
    29  	Time func() time.Time
    30  }
    31  
    32  func (c *Config) Random() io.Reader {
    33  	if c == nil || c.Rand == nil {
    34  		return rand.Reader
    35  	}
    36  	return c.Rand
    37  }
    38  
    39  func (c *Config) Hash() crypto.Hash {
    40  	if c == nil || uint(c.DefaultHash) == 0 {
    41  		return crypto.SHA256
    42  	}
    43  	return c.DefaultHash
    44  }
    45  
    46  func (c *Config) Cipher() CipherFunction {
    47  	if c == nil || uint8(c.DefaultCipher) == 0 {
    48  		return CipherAES128
    49  	}
    50  	return c.DefaultCipher
    51  }
    52  
    53  func (c *Config) Now() time.Time {
    54  	if c == nil || c.Time == nil {
    55  		return time.Now()
    56  	}
    57  	return c.Time()
    58  }