Esempio n. 1
0
  /**
   * Returns an instance of a padding algorithm given its name.
   *
   * @param pad the case-insensitive name of the padding algorithm.
   * @return an instance of the padding algorithm, operating with a given block size, or <code>null
   *     </code> if none found.
   * @throws InternalError if the implementation does not pass its self-test.
   */
  public static final IPad getInstance(String pad) {
    if (pad == null) return null;

    pad = pad.trim().toLowerCase();
    if (pad.endsWith("padding")) pad = pad.substring(0, pad.length() - "padding".length());
    IPad result = null;
    if (pad.equals(PKCS7_PAD) || pad.equals(PKCS5_PAD)) result = new PKCS7();
    else if (pad.equals(TBC_PAD)) result = new TBC();
    else if (pad.equals(EME_PKCS1_V1_5_PAD)) result = new PKCS1_V1_5();
    else if (pad.equals(SSL3_PAD)) result = new SSL3();
    else if (pad.equals(TLS1_PAD)) result = new TLS1();
    else if (pad.equals(ISO10126_PAD)) result = new ISO10126();

    if (result != null && !result.selfTest()) throw new InternalError(result.name());

    return result;
  }
 @Test
 public void shouldGetCorrectPriceForBlackIPad() {
   IPad iPad = new BlackIPad();
   assertThat(iPad.getPrice(), is(3688));
 }
 @Test
 public void shouldGetCorrectPriceForWhiteIPad() {
   IPad iPad = new WhiteIPad(new BlackIPad());
   assertThat(iPad.getPrice(), is(3688 + 200));
 }