| Crypt-OpenPGP documentation | Contained in the Crypt-OpenPGP distribution. |
Crypt::OpenPGP::Buffer - Binary in/out buffer
use Crypt::OpenPGP::Buffer;
my $n = Math::BigInt->new( 1 );
my $buf = Crypt::OpenPGP::Buffer->new;
$buf->put_big_int($n);
my $m = $buf->get_big_int;
Crypt::OpenPGP::Buffer subclasses the Data::Buffer class to provide binary in/out buffer capabilities for Crypt::OpenPGP. In addition to the standard Data::Buffer methods, this class adds methods to get and put multiple-precision integers (Math::BigInt objects).
A PGP multiple precision integer is stored in two pieces: a two-octet scalar representing the length of the integer in bits, followed by a string of octets that is a serialized representation of the integer.
As Crypt::OpenPGP::Buffer subclasses Data::Buffer there is no need to reproduce the entire documentation of the latter module. Thus this usage section will include only the methods added by Crypt::OpenPGP::Buffer.
Grabs a multiple-precision integer from the buffer $buf (starting after the current offset position in the buffer) and returns that integer.
get_mp_int() is an alias for this method, for backwards compatibility reasons.
Serializes a multiple-precision integer into the buffer in the above form (two-octet bitsize, string of octets).
put_mp_int() is an alias for this method, for backwards compatibility reasons.
Please see the Crypt::OpenPGP manpage for author, copyright, and license information.
| Crypt-OpenPGP documentation | Contained in the Crypt-OpenPGP distribution. |
package Crypt::OpenPGP::Buffer; use base qw( Data::Buffer ); use Crypt::OpenPGP::Util qw( bin2mp mp2bin bitsize ); sub get_big_int { my $buf = shift; my $bits = $buf->get_int16; my $bytes = int(($bits + 7) / 8); my $off = $buf->{offset}; $buf->{offset} += $bytes; my $int = bin2mp($buf->bytes($off, $bytes)); return "$int"; } sub put_big_int { my $buf = shift; my($n) = @_; $buf->put_int16(bitsize($n)); $buf->put_bytes(mp2bin($n)); } *get_mp_int = \&get_big_int; *put_mp_int = \&put_big_int; 1; __END__