Improve testing of MultiRecipientMessageProvider

This commit is contained in:
erik-signal
2022-10-17 16:50:39 -04:00
committed by GitHub
parent 378d7987a8
commit a7d5d51fb4
3 changed files with 113 additions and 15 deletions

View File

@@ -107,10 +107,11 @@ public class MultiRecipientMessageProvider implements MessageBodyReader<MultiRec
*
* @return the varint value
*/
private long readVarint(InputStream stream) throws IOException, WebApplicationException {
@VisibleForTesting
public static long readVarint(InputStream stream) throws IOException, WebApplicationException {
boolean hasMore = true;
int currentOffset = 0;
int result = 0;
long result = 0;
while (hasMore) {
if (currentOffset >= 64) {
throw new BadRequestException("varint is too large");
@@ -123,7 +124,7 @@ public class MultiRecipientMessageProvider implements MessageBodyReader<MultiRec
throw new BadRequestException("varint is too large");
}
hasMore = (b & 0x80) != 0;
result |= (b & 0x7F) << currentOffset;
result |= (b & 0x7FL) << currentOffset;
currentOffset += 7;
}
return result;