go.crypto/openpgp: fix nil Config case.

This is a followup to https://golang.org/cl/176080043/. That
change didn't handle the case of a *Config being nil.

CC=golang-codereviews
https://golang.org/cl/179200043
This commit is contained in:
Adam Langley
2014-11-21 14:11:46 -08:00
parent ca455997ca
commit f59690be3f
2 changed files with 8 additions and 1 deletions
+7
View File
@@ -79,3 +79,10 @@ func (c *Config) Compression() CompressionAlgo {
}
return c.DefaultCompressionAlgo
}
func (c *Config) PasswordHashIterations() int {
if c == nil || c.S2KCount == 0 {
return 0
}
return c.S2KCount
}
+1 -1
View File
@@ -120,7 +120,7 @@ func SerializeSymmetricKeyEncrypted(w io.Writer, passphrase []byte, config *Conf
keyEncryptingKey := make([]byte, keySize)
// s2k.Serialize salts and stretches the passphrase, and writes the
// resulting key to keyEncryptingKey and the s2k descriptor to s2kBuf.
err = s2k.Serialize(s2kBuf, keyEncryptingKey, config.Random(), passphrase, &s2k.Config{Hash: config.Hash(), S2KCount: config.S2KCount})
err = s2k.Serialize(s2kBuf, keyEncryptingKey, config.Random(), passphrase, &s2k.Config{Hash: config.Hash(), S2KCount: config.PasswordHashIterations()})
if err != nil {
return
}