Browse Source

i2p base64 encode/decode tool

pull/48/head
Jeff Becker 7 years ago
parent
commit
a148516d60
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
  1. 1
      .gitignore
  2. 7
      Makefile
  3. 85
      i2pbase64.cpp

1
.gitignore vendored

@ -9,6 +9,7 @@
keygen keygen
keyinfo keyinfo
famtool famtool
i2pbase64
# private key files # private key files
*.dat *.dat

7
Makefile

@ -13,7 +13,7 @@ OBJECTS = $(SOURCES:.cpp=.o)
I2PD_LIB = libi2pd.a I2PD_LIB = libi2pd.a
all: keygen keyinfo famtool routerinfo regaddr vain all: keygen keyinfo famtool routerinfo regaddr vain i2pbase64
routerinfo: $(OBJECTS) routerinfo: $(OBJECTS)
$(CXX) -o routerinfo routerinfo.o $(LDFLAGS) $(LIBS) $(CXX) -o routerinfo routerinfo.o $(LDFLAGS) $(LIBS)
@ -33,6 +33,9 @@ regaddr: $(OBJECTS)
vain: $(OBJECTS) vain: $(OBJECTS)
$(CXX) -o vain vanitygen.o $(LDFLAGS) -mavx $(LIBS) $(CXX) -o vain vanitygen.o $(LDFLAGS) -mavx $(LIBS)
i2pbase64: $(OBJECTS)
$(CXX) -o i2pbase64 i2pbase64.o $(LDFALGS) $(LIBS)
$(OBJECTS): libi2pd.a $(OBJECTS): libi2pd.a
.SUFFIXES: .SUFFIXES:
@ -54,7 +57,7 @@ clean-obj:
rm -f $(OBJECTS) rm -f $(OBJECTS)
clean-bin: clean-bin:
rm -f keyinfo keygen famtool regaddr routerinfo rm -f keyinfo keygen famtool regaddr routerinfo i2pbase64
clean: clean-i2pd clean-obj clean-bin clean: clean-i2pd clean-obj clean-bin

85
i2pbase64.cpp

@ -0,0 +1,85 @@
#include <unistd.h>
#include <fcntl.h>
#include <iostream>
#include <fstream>
#include <functional>
#include <cassert>
#include "Base.h"
const size_t BUFFSZ = 1024;
static int printHelp(const char * exe, int exitcode)
{
std::cout << "usage: " << exe << " [-d] [filename]" << std::endl;
return exitcode;
}
template <typename InCh, typename OutCh, size_t isz, size_t osz>
static int operate(std::function<std::size_t(const InCh *, size_t, OutCh *, size_t)> f, int infile, int outfile)
{
InCh inbuf[isz];
OutCh outbuf[osz];
ssize_t sz;
size_t outsz;
while((sz = read(infile, inbuf, sizeof(inbuf))) > 0)
{
outsz = f(inbuf, sz, outbuf, sizeof(outbuf));
if(outsz && outsz <= sizeof(outbuf))
{
write(outfile, outbuf, outsz);
}
else
{
return -1;
}
}
return errno;
}
int main(int argc, char * argv[])
{
int opt;
bool decode = false;
int infile = 0;
while((opt = getopt(argc, argv, "dh")) != -1)
{
switch(opt)
{
case 'h':
return printHelp(argv[0], 0);
case 'd':
decode = true;
break;
default:
continue;
}
}
if (argc - optind > 1)
{
return printHelp(argv[0], -1);
}
if (optind < argc)
{
infile = open(argv[optind], O_RDONLY);
if(infile == -1) {
perror(argv[optind]);
return -1;
}
}
int retcode = 0;
if(decode)
{
retcode = operate<char, uint8_t, BUFFSZ*4, BUFFSZ*3>(i2p::data::Base64ToByteStream, infile, 1);
}
else
{
retcode = operate<uint8_t, char, BUFFSZ*3, BUFFSZ*4>(&i2p::data::ByteStreamToBase64, infile, 1);
}
close(infile);
return retcode;
}
Loading…
Cancel
Save