diff --git a/src/crypto/crypto.cc b/src/crypto/crypto.cc index 50b60d9..9458de9 100644 --- a/src/crypto/crypto.cc +++ b/src/crypto/crypto.cc @@ -36,6 +36,7 @@ #include #include #include +#include #include "byteorder.h" #include "crypto.h" @@ -121,18 +122,12 @@ Base64Key::Base64Key( string printable_key ) Base64Key::Base64Key() { - FILE *devrandom = fopen( rdev, "r" ); - if ( devrandom == NULL ) { - throw CryptoException( string( rdev ) + ": " + strerror( errno ) ); - } + ifstream devrandom( rdev, ifstream::in | ifstream::binary ); - if ( 1 != fread( key, 16, 1, devrandom ) ) { + devrandom.read( reinterpret_cast( key ), sizeof( key ) ); + if ( !devrandom ) { throw CryptoException( "Could not read from " + string( rdev ) ); } - - if ( 0 != fclose( devrandom ) ) { - throw CryptoException( string( rdev ) + ": " + strerror( errno ) ); - } } string Base64Key::printable_key( void ) const