public void Test8Base92DigitsNeeds53Bits( ) { // Setup // Exercise BaseConverter converter = new BaseConverter( 92 ); // Verify Assert.That( converter.BytesNeeded( 8 ), Is.EqualTo( 7 ) ); }
public PasswordMaterializer( string symbols ) { if ( symbols == null ) throw new ArgumentNullException( "symbols" ); _symbols = symbols; _converter = new BaseConverter( _symbols.Length ); _passwordLength = ComputePasswordLength( _symbols.Length ); }
public void Test12Base64DigitsNeeds72Bits( ) { // Setup // Exercise BaseConverter converter = new BaseConverter( 64 ); // Verify Assert.That( converter.BytesNeeded( 12 ), Is.EqualTo( 9 ) ); }
public void TestCannotConvertWithNotEnoughBytes( ) { // Setup BaseConverter converter = new BaseConverter( 16 ); // Exercise // Verify Assert.That( new TestDelegate( ( ) => converter.ConvertBytesToDigits( new byte[ ] { 0x00, 0x00 }, 5 ) ), Throws.InstanceOf( typeof ( ArgumentException ) ) ); }
public void TestConvertArrayToSymbols64Returns12Characters( ) { // Setup const string symbols64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+"; PasswordMaterializer materializer = new PasswordMaterializer( symbols64 ); BaseConverter converter = new BaseConverter( 64 ); byte[ ] input = { 0xA1, 0x22, 0x44, 0x60, 0xE7, 0x01, 0x1A, 0x48, 0xCB }; byte[ ] convertedBytes = converter.ConvertBytesToDigits( input, 12 ); string expectedOutput = new string( convertedBytes.Select( b => symbols64[ b ] ).ToArray( ) ); // Exercise string output = materializer.ToString( input ); // Verify Assert.That( output, Is.EqualTo( expectedOutput ) ); }