# Copyright (c) 2000-2008 bivio Software, Inc. All rights reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: Base64.pm,v 2.3 2008/01/25 22:40:40 nagler Exp $ package Bivio::MIME::Base64; use strict; use Bivio::Base 'Bivio::UNIVERSAL'; use MIME::Base64 (); # C implements a web-safe encoding of base64, # which we call http-base64. The specials in Base64 are not # web friendly, so they are all replaced. our($VERSION) = sprintf('%d.%02d', q$Revision: 2.3 $ =~ /\d+/g); sub http_decode { # (self, string) : string # Converts I to an unencoded form using the rules for # http-base64 decoding. # # Returns C if the data couldn't be parsed. my(undef, $encoded) = @_; return undef unless $encoded && length($encoded) >= 4; $encoded =~ tr/_*-/=+\//; my($err) = 0; local($SIG{__WARN__}) = sub { $err++; Bivio::IO::Alert->warn(@_); return; }; my($res) = MIME::Base64::decode($encoded); return $err ? undef : $res; } sub http_encode { # (self, string) : string # Converts I to an encoded form using the rules for # http-base64 encoding. my(undef, $decoded) = @_; my($encoded) = MIME::Base64::encode($decoded, ''); $encoded =~ tr/=+\//_*-/; return $encoded; } 1;