class IntegerType extends AbstractDERType implements DEREncoder {

  public static int decodeUnsignedPrimitive(final DERBuffer encoded)
  {
    // CheckStyle:MagicNumber OFF
    final byte[] bytes = encoded.getRemainingBytes();
    if (bytes.length > 4) {
      throw new IllegalArgumentException("Buffer length must be <= 4 bytes");
    }
    int i = 0;
    for (byte b : bytes) {
      i <<= 8;
      i |= b & 0xFF;
    }
    return i;
    // CheckStyle:MagicNumber ON
  }

}

class IntegerTypeTest {

  @Test(groups = "asn1", dataProvider = "ints")
  public void decodeUnsignedPrimitive(
    final byte[] bytes, final BigInteger expected, final BigInteger unsigned, final int unsignedPrim)
    throws Exception
  {

    Assert.assertEquals(IntegerType.decodeUnsignedPrimitive(new DefaultDERBuffer(bytes)), unsignedPrim);
  }

}