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

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

Issue 5448065: code review 5448065: Add a []byte argument to hash.Hash to allow an allocati... (Closed)
Left Patch Set: diff -r 3c286b9b2206 https://go.googlecode.com/hg/ Created 13 years, 3 months ago
Right Patch Set: diff -r 5ef46981bf5e https://go.googlecode.com/hg/ Created 13 years, 3 months 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/packet/public_key.go ('k') | src/pkg/crypto/openpgp/packet/symmetrically_encrypted.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 packet 5 package packet
6 6
7 import ( 7 import (
8 "crypto" 8 "crypto"
9 "crypto/dsa" 9 "crypto/dsa"
10 error_ "crypto/openpgp/error" 10 error_ "crypto/openpgp/error"
11 "crypto/openpgp/s2k" 11 "crypto/openpgp/s2k"
12 "crypto/rand" 12 "crypto/rand"
13 "crypto/rsa" 13 "crypto/rsa"
14 "encoding/binary" 14 "encoding/binary"
15 "hash" 15 "hash"
16 "io" 16 "io"
17 "strconv" 17 "strconv"
18 "time"
18 ) 19 )
19 20
20 // Signature represents a signature. See RFC 4880, section 5.2. 21 // Signature represents a signature. See RFC 4880, section 5.2.
21 type Signature struct { 22 type Signature struct {
22 SigType SignatureType 23 SigType SignatureType
23 PubKeyAlgo PublicKeyAlgorithm 24 PubKeyAlgo PublicKeyAlgorithm
24 Hash crypto.Hash 25 Hash crypto.Hash
25 26
26 // HashSuffix is extra data that is hashed in after the signed data. 27 // HashSuffix is extra data that is hashed in after the signed data.
27 HashSuffix []byte 28 HashSuffix []byte
28 // HashTag contains the first two bytes of the hash for fast rejection 29 // HashTag contains the first two bytes of the hash for fast rejection
29 // of bad signed data. 30 // of bad signed data.
30 HashTag [2]byte 31 HashTag [2]byte
31 » CreationTime uint32 // Unix epoch time 32 » CreationTime time.Time
32 33
33 RSASignature parsedMPI 34 RSASignature parsedMPI
34 DSASigR, DSASigS parsedMPI 35 DSASigR, DSASigS parsedMPI
35 36
36 // rawSubpackets contains the unparsed subpackets, in order. 37 // rawSubpackets contains the unparsed subpackets, in order.
37 rawSubpackets []outputSubpacket 38 rawSubpackets []outputSubpacket
38 39
39 // The following are optional so are nil when not included in the 40 // The following are optional so are nil when not included in the
40 // signature. 41 // signature.
41 42
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 // parseSignatureSubpackets parses subpackets of the main signature packet. See 145 // parseSignatureSubpackets parses subpackets of the main signature packet. See
145 // RFC 4880, section 5.2.3.1. 146 // RFC 4880, section 5.2.3.1.
146 func parseSignatureSubpackets(sig *Signature, subpackets []byte, isHashed bool) (err error) { 147 func parseSignatureSubpackets(sig *Signature, subpackets []byte, isHashed bool) (err error) {
147 for len(subpackets) > 0 { 148 for len(subpackets) > 0 {
148 subpackets, err = parseSignatureSubpacket(sig, subpackets, isHas hed) 149 subpackets, err = parseSignatureSubpacket(sig, subpackets, isHas hed)
149 if err != nil { 150 if err != nil {
150 return 151 return
151 } 152 }
152 } 153 }
153 154
154 » if sig.CreationTime == 0 { 155 » if sig.CreationTime.IsZero() {
155 err = error_.StructuralError("no creation time in signature") 156 err = error_.StructuralError("no creation time in signature")
156 } 157 }
157 158
158 return 159 return
159 } 160 }
160 161
161 type signatureSubpacketType uint8 162 type signatureSubpacketType uint8
162 163
163 const ( 164 const (
164 creationTimeSubpacket signatureSubpacketType = 2 165 creationTimeSubpacket signatureSubpacketType = 2
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 switch packetType { 217 switch packetType {
217 case creationTimeSubpacket: 218 case creationTimeSubpacket:
218 if !isHashed { 219 if !isHashed {
219 err = error_.StructuralError("signature creation time in non-hashed area") 220 err = error_.StructuralError("signature creation time in non-hashed area")
220 return 221 return
221 } 222 }
222 if len(subpacket) != 4 { 223 if len(subpacket) != 4 {
223 err = error_.StructuralError("signature creation time no t four bytes") 224 err = error_.StructuralError("signature creation time no t four bytes")
224 return 225 return
225 } 226 }
226 » » sig.CreationTime = binary.BigEndian.Uint32(subpacket) 227 » » t := binary.BigEndian.Uint32(subpacket)
228 » » if t == 0 {
229 » » » sig.CreationTime = time.Time{}
230 » » } else {
231 » » » sig.CreationTime = time.Unix(int64(t), 0)
232 » » }
227 case signatureExpirationSubpacket: 233 case signatureExpirationSubpacket:
228 // Signature expiration time, section 5.2.3.10 234 // Signature expiration time, section 5.2.3.10
229 if !isHashed { 235 if !isHashed {
230 return 236 return
231 } 237 }
232 if len(subpacket) != 4 { 238 if len(subpacket) != 4 {
233 err = error_.StructuralError("expiration subpacket with bad length") 239 err = error_.StructuralError("expiration subpacket with bad length")
234 return 240 return
235 } 241 }
236 sig.SigLifetimeSecs = new(uint32) 242 sig.SigLifetimeSecs = new(uint32)
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 // outputSubpacket represents a subpacket to be marshaled. 540 // outputSubpacket represents a subpacket to be marshaled.
535 type outputSubpacket struct { 541 type outputSubpacket struct {
536 hashed bool // true if this subpacket is in the hashed area. 542 hashed bool // true if this subpacket is in the hashed area.
537 subpacketType signatureSubpacketType 543 subpacketType signatureSubpacketType
538 isCritical bool 544 isCritical bool
539 contents []byte 545 contents []byte
540 } 546 }
541 547
542 func (sig *Signature) buildSubpackets() (subpackets []outputSubpacket) { 548 func (sig *Signature) buildSubpackets() (subpackets []outputSubpacket) {
543 creationTime := make([]byte, 4) 549 creationTime := make([]byte, 4)
544 » creationTime[0] = byte(sig.CreationTime >> 24) 550 » binary.BigEndian.PutUint32(creationTime, uint32(sig.CreationTime.Unix()) )
545 » creationTime[1] = byte(sig.CreationTime >> 16)
546 » creationTime[2] = byte(sig.CreationTime >> 8)
547 » creationTime[3] = byte(sig.CreationTime)
548 subpackets = append(subpackets, outputSubpacket{true, creationTimeSubpac ket, false, creationTime}) 551 subpackets = append(subpackets, outputSubpacket{true, creationTimeSubpac ket, false, creationTime})
549 552
550 if sig.IssuerKeyId != nil { 553 if sig.IssuerKeyId != nil {
551 keyId := make([]byte, 8) 554 keyId := make([]byte, 8)
552 binary.BigEndian.PutUint64(keyId, *sig.IssuerKeyId) 555 binary.BigEndian.PutUint64(keyId, *sig.IssuerKeyId)
553 subpackets = append(subpackets, outputSubpacket{true, issuerSubp acket, false, keyId}) 556 subpackets = append(subpackets, outputSubpacket{true, issuerSubp acket, false, keyId})
554 } 557 }
555 558
556 return 559 return
557 } 560 }
LEFTRIGHT

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