@ -42,7 +42,7 @@ static const unsigned char _base64[] =
" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ " ;
" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ " ;
static int
static int
b64_encode ( const uint8 * src , unsigned len , uint8 * dst )
pg_ base 64_encode( const uint8 * src , unsigned len , uint8 * dst )
{
{
uint8 * p ,
uint8 * p ,
* lend = dst + 76 ;
* lend = dst + 76 ;
@ -92,7 +92,7 @@ b64_encode(const uint8 *src, unsigned len, uint8 *dst)
/* probably should use lookup table */
/* probably should use lookup table */
static int
static int
b64_decode ( const uint8 * src , unsigned len , uint8 * dst )
pg_ base 64_decode( const uint8 * src , unsigned len , uint8 * dst )
{
{
const uint8 * srcend = src + len ,
const uint8 * srcend = src + len ,
* s = src ;
* s = src ;
@ -160,7 +160,7 @@ b64_decode(const uint8 *src, unsigned len, uint8 *dst)
}
}
static unsigned
static unsigned
b64_enc_len ( unsigned srclen )
pg_ base 64_enc_len( unsigned srclen )
{
{
/*
/*
* 3 bytes will be converted to 4 , linefeed after 76 chars
* 3 bytes will be converted to 4 , linefeed after 76 chars
@ -169,7 +169,7 @@ b64_enc_len(unsigned srclen)
}
}
static unsigned
static unsigned
b64_dec_len ( unsigned srclen )
pg_ base 64_dec_len( unsigned srclen )
{
{
return ( srclen * 3 ) > > 2 ;
return ( srclen * 3 ) > > 2 ;
}
}
@ -218,11 +218,11 @@ pgp_armor_encode(const uint8 *src, unsigned len, StringInfo dst,
appendStringInfo ( dst , " %s: %s \n " , keys [ n ] , values [ n ] ) ;
appendStringInfo ( dst , " %s: %s \n " , keys [ n ] , values [ n ] ) ;
appendStringInfoChar ( dst , ' \n ' ) ;
appendStringInfoChar ( dst , ' \n ' ) ;
/* make sure we have enough room to b64_encode() */
/* make sure we have enough room to pg_ base 64_encode() */
b64len = b64_enc_len ( len ) ;
b64len = pg_ base 64_enc_len( len ) ;
enlargeStringInfo ( dst , ( int ) b64len ) ;
enlargeStringInfo ( dst , ( int ) b64len ) ;
res = b64_encode ( src , len , ( uint8 * ) dst - > data + dst - > len ) ;
res = pg_ base 64_encode( src , len , ( uint8 * ) dst - > data + dst - > len ) ;
if ( res > b64len )
if ( res > b64len )
elog ( FATAL , " overflow - encode estimate too small " ) ;
elog ( FATAL , " overflow - encode estimate too small " ) ;
dst - > len + = res ;
dst - > len + = res ;
@ -358,14 +358,14 @@ pgp_armor_decode(const uint8 *src, int len, StringInfo dst)
goto out ;
goto out ;
/* decode crc */
/* decode crc */
if ( b64_decode ( p + 1 , 4 , buf ) ! = 3 )
if ( pg_ base 64_decode( p + 1 , 4 , buf ) ! = 3 )
goto out ;
goto out ;
crc = ( ( ( long ) buf [ 0 ] ) < < 16 ) + ( ( ( long ) buf [ 1 ] ) < < 8 ) + ( long ) buf [ 2 ] ;
crc = ( ( ( long ) buf [ 0 ] ) < < 16 ) + ( ( ( long ) buf [ 1 ] ) < < 8 ) + ( long ) buf [ 2 ] ;
/* decode data */
/* decode data */
blen = ( int ) b64_dec_len ( len ) ;
blen = ( int ) pg_ base 64_dec_len( len ) ;
enlargeStringInfo ( dst , blen ) ;
enlargeStringInfo ( dst , blen ) ;
res = b64_decode ( base64_start , base64_end - base64_start , ( uint8 * ) dst - > data ) ;
res = pg_ base 64_decode( base64_start , base64_end - base64_start , ( uint8 * ) dst - > data ) ;
if ( res > blen )
if ( res > blen )
elog ( FATAL , " overflow - decode estimate too small " ) ;
elog ( FATAL , " overflow - decode estimate too small " ) ;
if ( res > = 0 )
if ( res > = 0 )