浏览代码

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
Adam Langley 11 年之前
父节点
当前提交
f59690be3f
共有 2 个文件被更改,包括 8 次插入1 次删除
  1. 7 0
      openpgp/packet/config.go
  2. 1 1
      openpgp/packet/symmetric_key_encrypted.go

+ 7 - 0
openpgp/packet/config.go

@@ -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
openpgp/packet/symmetric_key_encrypted.go

@@ -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
 	}