Recognize Barcode with Checksum Option from Storage

@param string $symbology Type of barcode.
@param string $checksumValidation Checksum validation parameter.

@return array
@throws Exception
964819
public function readWithChecksum($symbology, $checksumValidation)
    {
        if ($symbology == '')
            throw new Exception('Symbology not specified');

        if ($checksumValidation == '')
            throw new Exception('Checksum not specified');

        //build URI to read barcode
        $strURI = Product::$baseProductUri . '/barcode/' . $this->getFileName() . '/recognize?type=' . $symbology . '&checksumValidation=' . $checksumValidation;

        //sign URI
        $signedURI = Utils::sign($strURI);

        $responseStream = Utils::processCommand($signedURI, 'GET', '', '');

        $json = json_decode($responseStream);

        if ($json->Code == 200)
            return $json->Barcodes;
        else
            return false;
    }
565766
public String validate(String pAttributeName,
                           String pAttributeValue) {
        try {
            sEvaluator.setBypassCache(true);
            sEvaluator.parseExpressionString(pAttributeValue);
            sEvaluator.setBypassCache(false);
            return null;
        }
        catch (ELException exc) {
            return
                    MessageFormat.format
                            (Constants.ATTRIBUTE_PARSE_EXCEPTION,
                                            "" + pAttributeName,
                                            "" + pAttributeValue,
                                    exc.getMessage());
        }
    }
1195927
public function parse(string $validatorOutput, int $flags = Flags::NONE): OutputInterface
    {
        $sanitizer = new Sanitizer();
        $validatorOutput = trim($sanitizer->getSanitizedOutput($validatorOutput));

        $headerBodyParts = explode("\n", $validatorOutput, 2);
        $header = trim($headerBodyParts[0]);
        $body = trim($headerBodyParts[1]);

        if (ExceptionOutputParser::is($body)) {
            return ExceptionOutputParser::parse($body);
        }

        if ($this->isIncorrectUsageOutput($header)) {
            return new IncorrectUsageOutput();
        }

        $bodyXmlContent = $this->extractXmlContentFromBody($body);
        if (null === $bodyXmlContent) {
            throw new InvalidValidatorOutputException($validatorOutput);
        }

        $optionsParser = new OptionsParser();
        $options = $optionsParser->parse($header);

        if (null === $options) {
            $options = new Options(
                false,
                'ucn',
                'en',
                2,
                'all',
                'css3'
            );
        }

        $bodyDom = new \DOMDocument();
        $bodyDom->loadXML($bodyXmlContent);

        $observationResponseElement = $bodyDom->getElementsByTagName('observationresponse')->item(0);

        $observationResponseParser = new ObservationResponseParser();
        $observationResponse = $observationResponseParser->parse($observationResponseElement, $flags);

        return new ValidationOutput($options, $observationResponse);
    }
1000392
protected function calculateChecksum() {
        $this->checksumValue = 0;
        $c = strlen($this->text);
        for ($i = 0; $i < $c; $i++) {
            $this->checksumValue += $this->findIndex($this->text[$i]);
        }

        $this->checksumValue = $this->checksumValue % 43;
    }
440869
protected function validate()
    {
        $numberSymbols = $this->findSubtypes(Number::class);
        if (sizeof($numberSymbols) != 1) {
            throw new NotFoundException(
                'Error: Expected to contain one number class but found '.sizeof($numberSymbols)
            );
        }

        foreach ($this->symbols as $symbol) {
            if (sizeof($symbol->getIdentifiers()) == 0 and ! is_a($symbol, Number::class)) {
                throw new \LengthException('Error: AbstractSymbol does not have any identifiers');
            }
        }
    }
998600
public function _validation_valid_string($val, $flags = array('alpha', 'utf8'))
	{
		if ($this->_empty($val))
		{
			return true;
		}

		if ( ! is_array($flags))
		{
			if ($flags == 'alpha')
			{
				$flags = array('alpha', 'utf8');
			}
			elseif ($flags == 'alpha_numeric')
			{
				$flags = array('alpha', 'utf8', 'numeric');
			}
			elseif ($flags == 'url_safe')
			{
				$flags = array('alpha', 'numeric', 'dashes');
			}
			elseif ($flags == 'integer' or $flags == 'numeric')
			{
				$flags = array('numeric');
			}
			elseif ($flags == 'float')
			{
				$flags = array('numeric', 'dots');
			}
			elseif ($flags == 'quotes')
			{
				$flags = array('singlequotes', 'doublequotes');
			}
			elseif ($flags == 'slashes')
			{
				$flags = array('forwardslashes', 'backslashes');
			}
			elseif ($flags == 'all')
			{
				$flags = array('alpha', 'utf8', 'numeric', 'spaces', 'newlines', 'tabs', 'punctuation', 'singlequotes', 'doublequotes', 'dashes', 'forwardslashes', 'backslashes', 'brackets', 'braces');
			}
			else
			{
				return false;
			}
		}

		$pattern = ! in_array('uppercase', $flags) && in_array('alpha', $flags) ? 'a-z' : '';
		$pattern .= ! in_array('lowercase', $flags) && in_array('alpha', $flags) ? 'A-Z' : '';
		$pattern .= in_array('numeric', $flags) ? '0-9' : '';
		$pattern .= in_array('spaces', $flags) ? ' ' : '';
		$pattern .= in_array('newlines', $flags) ? "\n" : '';
		$pattern .= in_array('tabs', $flags) ? "\t" : '';
		$pattern .= in_array('dots', $flags) && ! in_array('punctuation', $flags) ? '\.' : '';
		$pattern .= in_array('commas', $flags) && ! in_array('punctuation', $flags) ? ',' : '';
		$pattern .= in_array('punctuation', $flags) ? "\.,\!\?:;\&" : '';
		$pattern .= in_array('dashes', $flags) ? '_\-' : '';
		$pattern .= in_array('forwardslashes', $flags) ? '\/' : '';
		$pattern .= in_array('backslashes', $flags) ? '\\\\' : '';
		$pattern .= in_array('singlequotes', $flags) ? "'" : '';
		$pattern .= in_array('doublequotes', $flags) ? "\"" : '';
		$pattern .= in_array('brackets', $flags) ? "\(\)" : '';
		$pattern .= in_array('braces', $flags) ? "\{\}" : '';
		$pattern = empty($pattern) ? '/^(.*)$/' : ('/^(['.$pattern.'])+$/');
		$pattern .= in_array('utf8', $flags) ? 'u' : '';

		return preg_match($pattern, $val) > 0;
	}
287738
private function validateMd5()
    {
        return static function (callable $handler) {
            return function (
                CommandInterface $c,
                RequestInterface $r = null
            ) use ($handler) {
                if ($c->getName() !== 'ReceiveMessage') {
                    return $handler($c, $r);
                }

                return $handler($c, $r)
                    ->then(
                        function ($result) use ($c, $r) {
                            foreach ((array) $result['Messages'] as $msg) {
                                $bodyMd5 = self::calculateBodyMd5($msg);
                                if (isset($msg['MD5OfBody'])
                                    && $bodyMd5 !== $msg['MD5OfBody']
                                ) {
                                    throw new SqsException(
                                        sprintf(
                                            'MD5 mismatch. Expected %s, found %s',
                                            $msg['MD5OfBody'],
                                            $bodyMd5
                                        ),
                                        $c,
                                        [
                                            'code' => 'ClientChecksumMismatch',
                                            'request' => $r
                                        ]
                                    );
                                }

                                if (isset($msg['MD5OfMessageAttributes'])) {
                                    $messageAttributesMd5 = self::calculateMessageAttributesMd5($msg);
                                    if ($messageAttributesMd5 !== $msg['MD5OfMessageAttributes']) {
                                        throw new SqsException(
                                            sprintf(
                                                'Attribute MD5 mismatch. Expected %s, found %s',
                                                $msg['MD5OfMessageAttributes'],
                                                $messageAttributesMd5
                                                    ? $messageAttributesMd5
                                                    : 'No Attributes'
                                            ),
                                            $c,
                                            [
                                                'code' => 'ClientChecksumMismatch',
                                                'request' => $r
                                            ]
                                        );
                                    }
                                } else if (isset($msg['MessageAttributes'])) {
                                    throw new SqsException(
                                        sprintf(
                                            'No Attribute MD5 found. Expected %s',
                                            self::calculateMessageAttributesMd5($msg)
                                        ),
                                        $c,
                                        [
                                            'code' => 'ClientChecksumMismatch',
                                            'request' => $r
                                        ]
                                    );
                                }
                            }
                            return $result;
                        }
                    );
            };
        };
    }
497857
function isValidIdentifierCharacter(ch) {
  if (!ch) {
    return false
  }

  return (
    0x2d == code(ch) || // '-'
    0x2e == code(ch) || // '.'
    0x3a == code(ch) || // ':'
    inRange(code(ch), 0x30, 0x39) || // 0-9 (DIGIT)
    inRange(code(ch), 0x61, 0x7a) || // a-z (ALPHA)
    inRange(code(ch), 0x41, 0x5a)    // A-Z (ALPHA)
  )
}
474693
protected function processChecksum() {
        if ($this->checksumValue === false) { // Calculate the checksum only once
            $this->calculateChecksum();
        }

        if ($this->checksumValue !== false) {
            return $this->keys[$this->checksumValue];
        }

        return false;
    }
707741
private function checksum($code)
	{
		$len = strlen($code);
		$sum = 0;
		for ($i = 0; $i < $len; $i += 2) {
			$sum += $code[$i];
		}
		$sum *= 3;
		for ($i = 1; $i < $len; $i += 2) {
			$sum += ($code[$i]);
		}
		$r = $sum % 10;
		if ($r > 0) {
			$r = (10 - $r);
		}
		return $r;
	}
719760
def _check_checksum(msg):
    """"""
    checksum = int(msg[-2:], 16)
    for char in msg[:-2]:
        checksum += ord(char)
    if (checksum % 256) != 0:
        raise ValueError("Elk message checksum invalid")
1008564
protected function validateOptions()
    {
        if (!isset($this->options['allowedTypes'])) {
            throw new InvalidValidationOptionsException('The option "allowedTypes" was not specified.', 1327947194);
        } elseif (!is_array($this->options['allowedTypes']) || $this->options['allowedTypes'] === []) {
            throw new InvalidValidationOptionsException('The option "allowedTypes" must be an array with at least one item.', 1327947224);
        }
    }
505689
public function validateNumber($creditCardNumber)
    {
        if (!$this->checkType()) {
            throw new Exception(Yii::t('ECCValidator', 'The "format" property must be specified with a supported Credit Card format.'));
        }

        $creditCardNumber = preg_replace('/[ -]+/', '', $creditCardNumber);

        return $this->checkFormat($creditCardNumber) && $this->mod10($creditCardNumber);
    }
1257730
public function checksums(array $checksums = null) {
        if ($checksums === null) {
            return $this->checksums;
        }

        $this->checksums = $checksums;

        return $this;
    }
395940
protected function assertValidCode($code)
    {
        if ($code instanceof Money) {
            $code = $code->getCurrency();
        }

        if ($code instanceof Currency) {
            return (string) $code;
        }

        if (!is_string($code)) {
            throw new Exception\InvalidArgumentException(sprintf(
                'Currency code should be a string; %s given',
                gettype($code)
            ));
        }

        $code = trim(strtoupper($code));
        if (!Currencies::exists($code)) {
            throw new Exception\UnknownCurrencyException(sprintf(
                '%s is not a valid ISO 4217 Currency code',
                $code
            ));
        }

        return $code;
    }
385566
protected function _rfc822IsAtext($chr, $validate = null)
    {
        if (!$this->_params['validate'] && !is_null($validate)) {
            return strcspn($chr, $validate);
        }

        $ord = ord($chr);

        /* UTF-8 characters check. */
        if ($ord > 127) {
            return ($this->_params['validate'] === 'eai');
        }

        /* Check for DISALLOWED characters under both RFCs 5322 and 6532. */

        /* Unprintable characters && [SPACE] */
        if ($ord <= 32) {
            return false;
        }

        /* "(),:;<>@[\] [DEL] */
        switch ($ord) {
        case 34:
        case 40:
        case 41:
        case 44:
        case 58:
        case 59:
        case 60:
        case 62:
        case 64:
        case 91:
        case 92:
        case 93:
        case 127:
            return false;
        }

        return true;
    }
1135743
function validateChecksum(fileName, checksum, cb) {
   if (isUndefined(checksum) || isUndefined(checksum.hashAlgorithm)) {
      cb();
      return;
   }

   if (isUndefined(checksum.inline) || isUndefined(checksum.inline.value)) {
      cb(new Error('Installed jobs agent only supports inline checksum value provided in job document'));
      return;
   }

   var hash;
   try {
      hash = crypto.createHash(checksum.hashAlgorithm);
   } catch (err) {
      cb(new Error('Unsupported checksum hash algorithm: ' + checksum.hashAlgorithm));
      return;
   }

   var stream = fs.createReadStream(fileName);

   stream.on('data', function (data) {
      hash.update(data, 'utf8');
   }).on('end', function () {
      if (hash.digest('hex') !== checksum.inline.value) {
         var err = new Error('Checksum mismatch');
         err.fileName = fileName;
         cb(err);
      } else {
         cb();
      }
   }).on('error', function (err) {
      err.fileName = fileName;
      cb(err);
   });
}