Integer::StringToInteger is accepting invalid(?) input

Tim Offermann <[email protected]>
Newsgroups gmane.comp.encryption.cryptopp
Message-ID <[email protected]>

Hi

I was wondering if the current behavior of StringToInteger is perhaps a 
little bit too "friendly" - honestly I would have expected some exceptions 
on (IMHO) invalid input:

Dec from '011b' : 3.
Dec from '012b' : 1. ! 

Oct from '04711o' : 4711o
Oct from '04811o' : 411o !

Hex from '08Ah' : 8ah
Hex from '08A.' : 8h !
Hex from '08A'  : 8h !!!

This is my code:

#include "integer.h"
#include <iostream>

int main(int argc, char *argv[])
{

    std::cout << "Dec from '011b' : " << std::dec << 
CryptoPP::Integer("011b") << std::endl;

    std::cout << "Dec from '012b' : " << std::dec << 
CryptoPP::Integer("012b") << " !" << std::endl;

    std::cout << "\n";

    std::cout << "Oct from '04711o' : " << std::oct << 
CryptoPP::Integer("04711o") << std::endl;

    std::cout << "Oct from '04811o' : " << std::oct << 
CryptoPP::Integer("04811o") << " !" << std::endl;

    std::cout << "\n";

    std::cout << "Hex from '08Ah' : " << std::hex << 
CryptoPP::Integer("08Ah") << std::endl;

    std::cout << "Hex from '08A.' : " << std::hex << 
CryptoPP::Integer("08A.") << " !" << std::endl;

    std::cout << "Hex from '08A'  : " << std::hex << 
CryptoPP::Integer("08A") << " !!!" << std::endl;

    return 0;
}

It might be that the intention behind this originally was to accept 
additional characters like ":" or "-" in between for better readability 
(e.g. "31-65-30-63h" as  "31653063h"). Out of my personal experience in the 
last days I would propose to limit this openess a little bit. Especially 
not allowing characters which are valid digits in one of the available 
notations might help prevent some (difficult to spot) usage error.

With best regards,
Tim Offermann

-- 
You received this message because you are subscribed to the Google Groups "Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/cryptopp-users/73b69299-1337-4be5-97a7-20f80f28a0c8n%40googlegroups.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.