Skip to content

Commit

Permalink
Merge branch 'master' into otsv
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-gruenbacher committed Jan 11, 2017
2 parents d01bdfd + fbc824e commit 6fff9c9
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/Tag.pm
Expand Up @@ -16,21 +16,22 @@
# <http://www.gnu.org/licenses/>.

package Tag;
use MIME::Base64;

require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(random_tag);
use strict;

sub random_tag($) {
my ($bytes) = @_;
my $tag;
my ($chars) = @_;
my $bytes = $chars * 3 / 4;
my $random;

open my $fh, '<', '/dev/urandom'
or die "/dev/urandom: $!\n";
(read $fh, $tag, $bytes) == $bytes
(read $fh, $random, $bytes) == $bytes
or die "/dev/urandom: $!\n";
$tag =~ s/(.)/sprintf("%02x",ord($1))/egs;

return $tag;
return encode_base64($random);
}

0 comments on commit 6fff9c9

Please sign in to comment.