update the codebase to latest go src (time, hash, strconv)
[epoint] / patches / sig.diff
1 diff -r 7ec969250bfc src/pkg/crypto/openpgp/packet/signature.go
2 --- a/src/pkg/crypto/openpgp/packet/signature.go        Tue Dec 27 09:49:19 2011 -0500
3 +++ b/src/pkg/crypto/openpgp/packet/signature.go        Fri Dec 30 22:56:55 2011 +0100
4 @@ -164,7 +164,7 @@
5  const (
6         creationTimeSubpacket        signatureSubpacketType = 2
7         signatureExpirationSubpacket signatureSubpacketType = 3
8 -       keyExpirySubpacket           signatureSubpacketType = 9
9 +       keyExpirationSubpacket       signatureSubpacketType = 9
10         prefSymmetricAlgosSubpacket  signatureSubpacketType = 11
11         issuerSubpacket              signatureSubpacketType = 16
12         prefHashAlgosSubpacket       signatureSubpacketType = 21
13 @@ -225,11 +225,7 @@
14                         return
15                 }
16                 t := binary.BigEndian.Uint32(subpacket)
17 -               if t == 0 {
18 -                       sig.CreationTime = time.Time{}
19 -               } else {
20 -                       sig.CreationTime = time.Unix(int64(t), 0)
21 -               }
22 +               sig.CreationTime = time.Unix(int64(t), 0)
23         case signatureExpirationSubpacket:
24                 // Signature expiration time, section 5.2.3.10
25                 if !isHashed {
26 @@ -241,7 +237,7 @@
27                 }
28                 sig.SigLifetimeSecs = new(uint32)
29                 *sig.SigLifetimeSecs = binary.BigEndian.Uint32(subpacket)
30 -       case keyExpirySubpacket:
31 +       case keyExpirationSubpacket:
32                 // Key expiration time, section 5.2.3.6
33                 if !isHashed {
34                         return
35 @@ -556,5 +552,59 @@
36                 subpackets = append(subpackets, outputSubpacket{true, issuerSubpacket, false, keyId})
37         }
38  
39 +       if sig.SigLifetimeSecs != nil && *sig.SigLifetimeSecs != 0 {
40 +               sigLifetime := make([]byte, 4)
41 +               binary.BigEndian.PutUint32(sigLifetime, *sig.SigLifetimeSecs)
42 +               // signature expiration is marked as critical
43 +               subpackets = append(subpackets, outputSubpacket{true, signatureExpirationSubpacket, true, sigLifetime})
44 +       }
45 +
46 +       // The following subpackets may only appear in self-signatures
47 +
48 +       if sig.KeyLifetimeSecs != nil && *sig.KeyLifetimeSecs != 0 {
49 +               keyLifetime := make([]byte, 4)
50 +               binary.BigEndian.PutUint32(keyLifetime, *sig.KeyLifetimeSecs)
51 +               // TODO:
52 +               // key expiration is marked as critical
53 +               subpackets = append(subpackets, outputSubpacket{true, keyExpirationSubpacket, true, keyLifetime})
54 +       }
55 +
56 +       if sig.IsPrimaryId != nil && *sig.IsPrimaryId {
57 +               subpackets = append(subpackets, outputSubpacket{true, primaryUserIdSubpacket, false, []byte{1}})
58 +       }
59 +
60 +       // []byte slices of preferred algorithms are not copied
61 +
62 +       if len(sig.PreferredSymmetric) > 0 {
63 +               subpackets = append(subpackets, outputSubpacket{true, prefSymmetricAlgosSubpacket, false, sig.PreferredSymmetric})
64 +       }
65 +
66 +       if len(sig.PreferredHash) > 0 {
67 +               subpackets = append(subpackets, outputSubpacket{true, prefHashAlgosSubpacket, false, sig.PreferredHash})
68 +       }
69 +
70 +       if len(sig.PreferredCompression) > 0 {
71 +               subpackets = append(subpackets, outputSubpacket{true, prefCompressionSubpacket, false, sig.PreferredCompression})
72 +       }
73 +
74 +       // The Key Flags subpacket may only appear in self-signatures or certification signatures
75 +
76 +       if sig.FlagsValid {
77 +               flags := byte(0)
78 +               if sig.FlagCertify {
79 +                       flags |= 1
80 +               }
81 +               if sig.FlagSign {
82 +                       flags |= 2
83 +               }
84 +               if sig.FlagEncryptCommunications {
85 +                       flags |= 4
86 +               }
87 +               if sig.FlagEncryptStorage {
88 +                       flags |= 8
89 +               }
90 +               subpackets = append(subpackets, outputSubpacket{true, keyFlagsSubpacket, false, []byte{flags}})
91 +       }
92 +
93         return
94  }