LEFT | RIGHT |
1 // Copyright 2012 The Go Authors. All rights reserved. | 1 // Copyright 2012 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package packet | 5 package packet |
6 | 6 |
7 import ( | 7 import ( |
8 "crypto" | 8 "crypto" |
9 "crypto/rand" | 9 "crypto/rand" |
10 "io" | 10 "io" |
(...skipping 12 matching lines...) Expand all Loading... |
23 // DefaultCipher is the cipher to be used. | 23 // DefaultCipher is the cipher to be used. |
24 // If zero, AES-128 is used. | 24 // If zero, AES-128 is used. |
25 DefaultCipher CipherFunction | 25 DefaultCipher CipherFunction |
26 // Time returns the current time as the number of seconds since the | 26 // Time returns the current time as the number of seconds since the |
27 // epoch. If Time is nil, time.Now is used. | 27 // epoch. If Time is nil, time.Now is used. |
28 Time func() time.Time | 28 Time func() time.Time |
29 // DefaultCompressionAlgo is the compression algorithm to be | 29 // DefaultCompressionAlgo is the compression algorithm to be |
30 // applied to the plaintext before encryption. If zero, no | 30 // applied to the plaintext before encryption. If zero, no |
31 // compression is done. | 31 // compression is done. |
32 DefaultCompressionAlgo CompressionAlgo | 32 DefaultCompressionAlgo CompressionAlgo |
33 » // DefaultCompressionConfig configures the compression | 33 » // CompressionConfig configures the compression settings. |
34 » // settings. CompressionConfig.Level must be set to between -1 | 34 » CompressionConfig *CompressionConfig |
35 » // and 9, otherwise a non-nil error will be returned during | |
36 » // encryption. A -1 value for CompressConfig.Level causes the | |
37 » // default compression level to be used, 0 means no | |
38 » // compression (the compressor will store the data as-is) and | |
39 » // 1 to 9 cause increasing (better, slower) compression levels | |
40 » // to be used (See the constants above for convenient common | |
41 » // settings). If nil and compression is in effect, | |
42 » // DefaultCompression is the level of compression used. | |
43 » DefaultCompressionConfig *CompressionConfig | |
44 } | 35 } |
45 | 36 |
46 func (c *Config) Random() io.Reader { | 37 func (c *Config) Random() io.Reader { |
47 if c == nil || c.Rand == nil { | 38 if c == nil || c.Rand == nil { |
48 return rand.Reader | 39 return rand.Reader |
49 } | 40 } |
50 return c.Rand | 41 return c.Rand |
51 } | 42 } |
52 | 43 |
53 func (c *Config) Hash() crypto.Hash { | 44 func (c *Config) Hash() crypto.Hash { |
(...skipping 16 matching lines...) Expand all Loading... |
70 } | 61 } |
71 return c.Time() | 62 return c.Time() |
72 } | 63 } |
73 | 64 |
74 func (c *Config) Compression() CompressionAlgo { | 65 func (c *Config) Compression() CompressionAlgo { |
75 if c == nil { | 66 if c == nil { |
76 return CompressionNone | 67 return CompressionNone |
77 } | 68 } |
78 return c.DefaultCompressionAlgo | 69 return c.DefaultCompressionAlgo |
79 } | 70 } |
80 | |
81 func (c *Config) CompressionLevel() int { | |
82 if c == nil || c.DefaultCompressionConfig == nil { | |
83 return DefaultCompression | |
84 } | |
85 | |
86 return c.DefaultCompressionConfig.Level | |
87 } | |
LEFT | RIGHT |