Skip to content

Commit

Permalink
[backend] add asn1_integer_mpi to encode a mpi integer
Browse files Browse the repository at this point in the history
  • Loading branch information
mlschroe committed Nov 27, 2017
1 parent 461ce97 commit 9d45651
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/backend/BSASN1.pm
Expand Up @@ -140,6 +140,13 @@ sub asn1_integer {
return asn1_pack($INTEGER, substr(pack('N', $_[0]), 3 - (length(sprintf('%b', $_[0] >= 0 ? $_[0] : ~$_[0])) >> 3)));
}

sub asn1_integer_mpi {
my $mpi = $_[0];
$mpi = pack('C', 0) if length($mpi) == 0;
$mpi = substr($mpi, 1) while length($mpi) > 1 && unpack('C', $mpi) == 0;
return asn1_pack($INTEGER, unpack('C', $mpi) >= 128 ? pack('C', 0).$mpi : $mpi);
}

sub asn1_obj_id {
my ($o1, $o2, @o) = @_;
return asn1_pack($OBJ_ID, pack('w*', $o1 * 40 + $o2, @o));
Expand Down

0 comments on commit 9d45651

Please sign in to comment.