diff --git a/.gitignore b/.gitignore index f31fffe..4ac9a3e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ keygen keyinfo famtool +i2pbase64 # private key files *.dat diff --git a/Makefile b/Makefile index 482541b..131814a 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ OBJECTS = $(SOURCES:.cpp=.o) I2PD_LIB = libi2pd.a -all: keygen keyinfo famtool routerinfo regaddr vain +all: keygen keyinfo famtool routerinfo regaddr vain i2pbase64 routerinfo: $(OBJECTS) $(CXX) -o routerinfo routerinfo.o $(LDFLAGS) $(LIBS) @@ -33,6 +33,9 @@ regaddr: $(OBJECTS) vain: $(OBJECTS) $(CXX) -o vain vanitygen.o $(LDFLAGS) -mavx $(LIBS) +i2pbase64: $(OBJECTS) + $(CXX) -o i2pbase64 i2pbase64.o $(LDFALGS) $(LIBS) + $(OBJECTS): libi2pd.a .SUFFIXES: @@ -54,7 +57,7 @@ clean-obj: rm -f $(OBJECTS) clean-bin: - rm -f keyinfo keygen famtool regaddr routerinfo + rm -f keyinfo keygen famtool regaddr routerinfo i2pbase64 clean: clean-i2pd clean-obj clean-bin diff --git a/i2pbase64.cpp b/i2pbase64.cpp new file mode 100644 index 0000000..de8386d --- /dev/null +++ b/i2pbase64.cpp @@ -0,0 +1,85 @@ +#include +#include +#include +#include +#include +#include +#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 +static int operate(std::function 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(i2p::data::Base64ToByteStream, infile, 1); + } + else + { + retcode = operate(&i2p::data::ByteStreamToBase64, infile, 1); + } + close(infile); + return retcode; +}