Issue 1376 Check EAN13 checksum when encoding

git-svn-id: https://zxing.googlecode.com/svn/trunk@2454 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2012-10-10 20:32:05 +00:00
parent 191f541f4a
commit 91a71dba0b
2 changed files with 9 additions and 1 deletions

View file

@ -18,6 +18,7 @@ package com.google.zxing.oned;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.FormatException;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
@ -55,6 +56,13 @@ public final class EAN13Writer extends UPCEANWriter {
throw new IllegalArgumentException(
"Requested contents should be 13 digits long, but got " + contents.length());
}
try {
if (!UPCEANReader.checkStandardUPCEANChecksum(contents)) {
throw new IllegalArgumentException("Contents do not pass checksum");
}
} catch (FormatException fe) {
throw new IllegalArgumentException("Illegal contents");
}
int firstDigit = Integer.parseInt(contents.substring(0, 1));
int parities = EAN13Reader.FIRST_DIGIT_ENCODINGS[firstDigit];

View file

@ -224,7 +224,7 @@ public abstract class UPCEANReader extends OneDReader {
* @return true iff string of digits passes the UPC/EAN checksum algorithm
* @throws FormatException if the string does not contain only digits
*/
private static boolean checkStandardUPCEANChecksum(CharSequence s) throws FormatException {
static boolean checkStandardUPCEANChecksum(CharSequence s) throws FormatException {
int length = s.length();
if (length == 0) {
return false;