LEFT | RIGHT |
(no file at all) | |
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 // This package implements parsing and serialisation of OpenPGP packets, as | 5 // This package implements parsing and serialisation of OpenPGP packets, as |
6 // specified in RFC 4880. | 6 // specified in RFC 4880. |
7 package packet | 7 package packet |
8 | 8 |
9 import ( | 9 import ( |
| 10 "big" |
10 "crypto/aes" | 11 "crypto/aes" |
11 "crypto/cast5" | 12 "crypto/cast5" |
12 "crypto/cipher" | 13 "crypto/cipher" |
13 "crypto/openpgp/error" | 14 "crypto/openpgp/error" |
14 "io" | 15 "io" |
15 "os" | 16 "os" |
16 ) | 17 ) |
17 | 18 |
18 // readFull is the same as io.ReadFull except that reading zero bytes returns | 19 // readFull is the same as io.ReadFull except that reading zero bytes returns |
19 // ErrUnexpectedEOF rather than EOF. | 20 // ErrUnexpectedEOF rather than EOF. |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 if err != nil { | 379 if err != nil { |
379 return | 380 return |
380 } | 381 } |
381 bitLength = uint16(buf[0])<<8 | uint16(buf[1]) | 382 bitLength = uint16(buf[0])<<8 | uint16(buf[1]) |
382 numBytes := (int(bitLength) + 7) / 8 | 383 numBytes := (int(bitLength) + 7) / 8 |
383 mpi = make([]byte, numBytes) | 384 mpi = make([]byte, numBytes) |
384 _, err = readFull(r, mpi) | 385 _, err = readFull(r, mpi) |
385 return | 386 return |
386 } | 387 } |
387 | 388 |
388 // writeMPI serializes a big integer to r. | 389 // writeMPI serializes a big integer to w. |
389 func writeMPI(w io.Writer, bitLength uint16, mpiBytes []byte) (err os.Error) { | 390 func writeMPI(w io.Writer, bitLength uint16, mpiBytes []byte) (err os.Error) { |
390 _, err = w.Write([]byte{byte(bitLength >> 8), byte(bitLength)}) | 391 _, err = w.Write([]byte{byte(bitLength >> 8), byte(bitLength)}) |
391 if err == nil { | 392 if err == nil { |
392 _, err = w.Write(mpiBytes) | 393 _, err = w.Write(mpiBytes) |
393 } | 394 } |
394 return | 395 return |
395 } | 396 } |
| 397 |
| 398 // writeBig serializes a *big.Int to w. |
| 399 func writeBig(w io.Writer, i *big.Int) os.Error { |
| 400 return writeMPI(w, uint16(i.BitLen()), i.Bytes()) |
| 401 } |
LEFT | RIGHT |