( XStorage xParentStorage,
String sName,
String sMediaType,
byte[] pBytes,
byte[] pPass )
| 485 | } |
| 486 | |
| 487 | public boolean checkEncrStream( XStorage xParentStorage, |
| 488 | String sName, |
| 489 | String sMediaType, |
| 490 | byte[] pBytes, |
| 491 | byte[] pPass ) |
| 492 | { |
| 493 | // Important: a common password for any of parent storage should not be set or |
| 494 | // should be different from pPass |
| 495 | |
| 496 | if ( pPass.length == 0 ) |
| 497 | { |
| 498 | Error( "Wrong password is used in the test!" ); |
| 499 | return false; |
| 500 | } |
| 501 | |
| 502 | try |
| 503 | { |
| 504 | xParentStorage.openStreamElement( sName, ElementModes.READ ); |
| 505 | Error( "Encrypted stream '" + sName + "' was opened without password!" ); |
| 506 | return false; |
| 507 | } |
| 508 | catch( WrongPasswordException wpe ) |
| 509 | {} |
| 510 | catch( Exception e ) |
| 511 | { |
| 512 | Error( "Unexpected exception in case of opening of encrypted stream '" + sName + "' without password: " + e + "!" ); |
| 513 | return false; |
| 514 | } |
| 515 | |
| 516 | byte pWrongPass[] = { 1, 1 }; |
| 517 | pWrongPass[0] += pPass[0]; |
| 518 | try |
| 519 | { |
| 520 | xParentStorage.openEncryptedStreamElement( sName, ElementModes.READ, new String(pWrongPass) ); |
| 521 | Error( "Encrypted stream '" + sName + "' was opened with wrong password!" ); |
| 522 | return false; |
| 523 | } |
| 524 | catch( WrongPasswordException wpe ) |
| 525 | {} |
| 526 | catch( Exception e ) |
| 527 | { |
| 528 | Error( "Unexpected exception in case of opening of encrypted stream '" + sName + "' with wrong password: " + e + "!" ); |
| 529 | return false; |
| 530 | } |
| 531 | |
| 532 | XStream xSubStream = null; |
| 533 | try |
| 534 | { |
| 535 | Object oSubStream = xParentStorage.openEncryptedStreamElement( sName, ElementModes.READ, new String(pPass) ); |
| 536 | xSubStream = UnoRuntime.queryInterface( XStream.class, oSubStream ); |
| 537 | if ( xSubStream == null ) |
| 538 | { |
| 539 | Error( "Can't open encrypted substream '" + sName + "'!" ); |
| 540 | return false; |
| 541 | } |
| 542 | } |
| 543 | catch( Exception e ) |
| 544 | { |
no test coverage detected