Class OffsetAssertions


  • public final class OffsetAssertions
    extends java.lang.Object
    Buffers and assertions for the operations that take a byte-array offset, exercised at a non-zero offset.

    Every offset the abstraction layer receives is zero in the rest of the suite, so a backend that drops an + offset produces the right answer everywhere and is never caught. A case built on this class asserts three things: that the result lands at the requested offset, that it is the expected value, and that the bytes around it are untouched. The last one is what a dropped output offset breaks. The decoy bytes placed before every input are what a dropped input offset breaks, and the ones placed after it are what an ignored input length breaks.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int INPUT_OFFSET
      The offset at which the payload starts in every input array.
      static int OUTPUT_OFFSET
      The offset at which every result is asked to land.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void assertResultAt​(java.lang.String label, byte[] output, int offset, byte[] expected)
      Asserts that the expected result sits at the given offset of the output, and that every byte before the offset and every byte past the result still holds the canary.
      static void assertUntouchedBefore​(java.lang.String label, byte[] output, int offset)
      Asserts that every byte before the given offset still holds the canary.
      static void assertUntouchedFrom​(java.lang.String label, byte[] output, int from)
      Asserts that every byte from the given index to the end of the output still holds the canary.
      static byte[] canaryFilled​(int length)
      Returns an array of the given length filled with the canary.
      static byte[] outputFor​(int resultLength)
      Returns a canary-filled output with room for a result of the given length at OUTPUT_OFFSET and slack past it.
      static byte[] resultAt​(byte[] output, int offset, int length)
      Copies a result out of an output array.
      static byte[] withDecoysAround​(byte[] payload)
      Surrounds the given bytes with decoy bytes, so that an operation reading from offset zero, or reading to the end of the array, processes something different rather than the same thing.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • INPUT_OFFSET

        public static final int INPUT_OFFSET
        The offset at which the payload starts in every input array.
        See Also:
        Constant Field Values
      • OUTPUT_OFFSET

        public static final int OUTPUT_OFFSET
        The offset at which every result is asked to land.
        See Also:
        Constant Field Values
    • Method Detail

      • withDecoysAround

        public static byte[] withDecoysAround​(byte[] payload)
        Surrounds the given bytes with decoy bytes, so that an operation reading from offset zero, or reading to the end of the array, processes something different rather than the same thing.
        Parameters:
        payload - the bytes the operation is meant to read
        Returns:
        a new array holding the payload at INPUT_OFFSET, with decoy bytes before and after it
      • outputFor

        public static byte[] outputFor​(int resultLength)
        Returns a canary-filled output with room for a result of the given length at OUTPUT_OFFSET and slack past it.
        Parameters:
        resultLength - the room the operation requires for its result
        Returns:
        a new canary-filled array
      • canaryFilled

        public static byte[] canaryFilled​(int length)
        Returns an array of the given length filled with the canary.
        Parameters:
        length - the length of the array
        Returns:
        a new canary-filled array
      • resultAt

        public static byte[] resultAt​(byte[] output,
                                      int offset,
                                      int length)
        Copies a result out of an output array.
        Parameters:
        output - the array the operation wrote into
        offset - the offset at which the result starts
        length - the length of the result
        Returns:
        a new array holding the result
      • assertResultAt

        public static void assertResultAt​(java.lang.String label,
                                          byte[] output,
                                          int offset,
                                          byte[] expected)
        Asserts that the expected result sits at the given offset of the output, and that every byte before the offset and every byte past the result still holds the canary.
        Parameters:
        label - the operation, for the assertion messages
        output - the array the operation wrote into
        offset - the offset the operation was asked to write at
        expected - the expected result
      • assertUntouchedBefore

        public static void assertUntouchedBefore​(java.lang.String label,
                                                 byte[] output,
                                                 int offset)
        Asserts that every byte before the given offset still holds the canary.
        Parameters:
        label - the operation, for the assertion messages
        output - the array the operation wrote into
        offset - the offset the operation was asked to write at
      • assertUntouchedFrom

        public static void assertUntouchedFrom​(java.lang.String label,
                                               byte[] output,
                                               int from)
        Asserts that every byte from the given index to the end of the output still holds the canary.
        Parameters:
        label - the operation, for the assertion messages
        output - the array the operation wrote into
        from - the first index past the result