Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3)

Delta Between Two Patch Sets: src/pkg/crypto/openpgp/write.go

Issue 3989052: code review 3989052: crypto/openpgp: add package. (Closed)
Left Patch Set: code review 3989052: crypto/openpgp: API pre-review Created 14 years, 1 month ago
Right Patch Set: diff -r a2846f4a9040 https://go.googlecode.com/hg/ Created 14 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/crypto/openpgp/read_test.go ('k') | src/pkg/crypto/openpgp/write_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2011 The Go Authors. All rights reserved. 1 // Copyright 2011 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 openpgp 5 package openpgp
6 6
7 import ( 7 import (
8 "crypto" 8 "crypto"
9 "crypto/openpgp/armor" 9 "crypto/openpgp/armor"
10 "crypto/openpgp/error" 10 "crypto/openpgp/error"
11 "crypto/openpgp/packet" 11 "crypto/openpgp/packet"
12 "crypto/rand"
13 "crypto/rsa" 12 "crypto/rsa"
14 _ "crypto/sha256" 13 _ "crypto/sha256"
15 "io" 14 "io"
16 "os" 15 "os"
17 "strconv" 16 "strconv"
18 "time" 17 "time"
19 ) 18 )
20 19
21 // DetachSign signs message with the private key from signer (which must 20 // DetachSign signs message with the private key from signer (which must
22 // already have been decrypted) and writes the signature to w. 21 // already have been decrypted) and writes the signature to w.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 return error.InvalidArgumentError("signing key is encrypted") 63 return error.InvalidArgumentError("signing key is encrypted")
65 } 64 }
66 65
67 sig := new(packet.Signature) 66 sig := new(packet.Signature)
68 sig.SigType = sigType 67 sig.SigType = sigType
69 sig.PubKeyAlgo = signer.PrivateKey.PubKeyAlgo 68 sig.PubKeyAlgo = signer.PrivateKey.PubKeyAlgo
70 sig.Hash = crypto.SHA256 69 sig.Hash = crypto.SHA256
71 sig.CreationTime = uint32(time.Seconds()) 70 sig.CreationTime = uint32(time.Seconds())
72 sig.IssuerKeyId = &signer.PrivateKey.KeyId 71 sig.IssuerKeyId = &signer.PrivateKey.KeyId
73 72
74 » err = sig.BuildHashSuffix() 73 » h, wrappedHash, err := hashForSignature(sig.Hash, sig.SigType)
75 » if err != nil {
76 » » return
77 » }
78
79 » h, wrappedHash, err := getHashForSignature(sig.Hash, sig.SigType)
80 if err != nil { 74 if err != nil {
81 return 75 return
82 } 76 }
83 io.Copy(wrappedHash, message) 77 io.Copy(wrappedHash, message)
84 h.Write(sig.HashSuffix)
85 digest := h.Sum()
86 copy(sig.HashTag[:], digest)
87 78
88 switch signer.PrivateKey.PubKeyAlgo { 79 switch signer.PrivateKey.PubKeyAlgo {
89 case packet.PubKeyAlgoRSA, packet.PubKeyAlgoRSASignOnly: 80 case packet.PubKeyAlgoRSA, packet.PubKeyAlgoRSASignOnly:
90 priv := signer.PrivateKey.PrivateKey.(*rsa.PrivateKey) 81 priv := signer.PrivateKey.PrivateKey.(*rsa.PrivateKey)
91 » » sig.Signature, err = rsa.SignPKCS1v15(rand.Reader, priv, sig.Has h, digest) 82 » » err = sig.SignRSA(h, priv)
92 default: 83 default:
93 err = error.UnsupportedError("public key algorithm: " + strconv. Itoa(int(sig.PubKeyAlgo))) 84 err = error.UnsupportedError("public key algorithm: " + strconv. Itoa(int(sig.PubKeyAlgo)))
94 } 85 }
95 86
96 if err != nil { 87 if err != nil {
97 return 88 return
98 } 89 }
99 90
100 » return sig.Serialise(w) 91 » return sig.Serialize(w)
101 } 92 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b