Decodes the given raw track data

@param \Orkestra\Transactor\Entity\Account\SwipedCardAccount $account
@param string                                                $rawTrackData

@throws \Orkestra\Transactor\Exception\DecoderException
195546
public function decode(SwipedCardAccount $account, $rawTrackData)
    {
        if (!$account instanceof EncryptedSwipedCardAccount) {
            throw new DecoderException('Unable to populate account with data. An EncryptedSwipedCardAccount is necessary to decode encrypted track data.');
        }

        $bytes = str_split($rawTrackData);

        $position         = 0;
        $initialized      = false;
        $trackOneLength   = $trackOneLengthRounded   = 0;
        $trackTwoLength   = $trackTwoLengthRounded   = 0;
        $trackThreeLength = $trackThreeLengthRounded = 0;

        foreach ($bytes as $byte) {
            if (0 === $position && "\x02" !== $byte) {
                throw DecoderException::malformedTrackData();

            } elseif (5 === $position) {
                $trackOneLength        = ord($byte);
                $trackOneLengthRounded = ceil($trackOneLength / 8) * 8;

            } elseif (6 === $position) {
                $trackTwoLength        = ord($byte);
                $trackTwoLengthRounded = ceil($trackTwoLength / 8) * 8;

            } elseif (7 === $position) {
                $trackThreeLength        = ord($byte);
                $trackThreeLengthRounded = ceil($trackThreeLength / 8) * 8;

            } elseif (10 <= $position) {
                $initialized = true;

                break;
            }

            $position++;
        }

        if (!$initialized) {
            throw DecoderException::malformedTrackData();
        }

        $maskedTracks = substr($rawTrackData, 10, $trackOneLength + $trackTwoLength + $trackThreeLength);

        $position = 10 + $trackOneLength + $trackTwoLength + $trackThreeLength;
        $encryptedTrackOne = substr($rawTrackData, $position, $trackOneLengthRounded);
        $position += $trackOneLengthRounded;
        $encryptedTrackTwo = substr($rawTrackData, $position, $trackTwoLengthRounded);
        $position += $trackTwoLengthRounded;
        $encryptedTrackThree = substr($rawTrackData, $position, $trackThreeLengthRounded);

        $position += $trackThreeLengthRounded + 10;
        $ksn = substr($rawTrackData, $position, 10);

        $this->iso7813Decoder->decode($account, $maskedTracks);
        $account->setTrackOne($encryptedTrackOne);
        $account->setTrackTwo($encryptedTrackTwo);
        $account->setTrackThree($encryptedTrackThree);
        $account->setFormat(self::ENCRYPTION_FORMAT);
        $account->setKeySerialNumber($ksn);
    }
1301861
public static Tracker parseTracker(JSONObject object) throws JSONException {
		final int id = JsonInput.getInt(object, "id");
		final String name = JsonInput.getStringNotNull(object, "name");
		return new Tracker(id, name);
	}
284870
public function decryptData($encryptedData, $iv, &$data)
    {
        if (strlen($this->sessionKey) != 24) {
            return \ErrorCode::$IllegalAesKey;
        }
        $aesKey = base64_decode($this->sessionKey);
        if (strlen($iv) != 24) {
            return \ErrorCode::$IllegalIv;
        }
        $aesIV = base64_decode($iv);
        $aesCipher = base64_decode($encryptedData);
        $result = openssl_decrypt($aesCipher, "AES-128-CBC", $aesKey, 1, $aesIV);
        $dataObj = json_decode($result);
        if ($dataObj == null) {
            return \ErrorCode::$IllegalBuffer;
        }
        if ($dataObj->watermark->appid != $this->appid) {
            return \ErrorCode::$IllegalBuffer;
        }
        $data = $result;
        return \ErrorCode::$OK;
    }
1032825
public function decode($iv, $sessionKey, $encryptedData)
    {
        require_once __DIR__ . DIRECTORY_SEPARATOR . 'crypt' . DIRECTORY_SEPARATOR . 'wxBizDataCrypt.php';
        $pc = new \WXBizDataCrypt($this->config->get('appid'), $sessionKey);
        $errCode = $pc->decryptData($encryptedData, $iv, $data);
        if ($errCode == 0) {
            return json_decode($data, true);
        }
        return false;
    }
874179
public static function filter($rawData)
    {
        return is_array($rawData)

            ? array_map(
                function ($value) {
                    return \Pimf\Util\Character\Clean::xss($value);
                }, $rawData
            )

            : \Pimf\Util\Character\Clean::xss($rawData);
    }
600715
public static String encryptTrack(String trackData, String encoding) {
		return SecureUtil.encryptData(trackData, encoding,
				CertUtil.getEncryptTrackPublicKey());
	}
575896
public function getRawChangeAddress($account)
    {
        $args = [
            (string)$account
        ];
        return $this->rpc->query(__FUNCTION__, $args);
    }
470398
protected function _decodeAttachment(&$data, &$attachment_data)
    {
        $attribute = $this->_geti($data, 32);

        switch ($attribute) {
        case self::ARENDDATA:
            /* Marks start of new attachment. */
            $this->_getx($data, $this->_geti($data, 32));

            /* Checksum */
            $this->_geti($data, 16);

            /* Add a new default data block to hold details of this
               attachment. Reverse order is easier to handle later! */
            array_unshift($attachment_data, array('type'    => 'application',
                                                  'subtype' => 'octet-stream',
                                                  'name'    => 'unknown',
                                                  'stream'  => ''));
            break;

        case self::AFILENAME:
            $value = $this->_getx($data, $this->_geti($data, 32));
            $value = $this->convertString($value, true);

            /* Strip path. */
            $attachment_data[0]['name'] = preg_replace('/.*[\/](.*)$/', '\1', $value);

            /* Checksum */
            $this->_geti($data, 16);
            break;

        case self::ATTACHDATA:
            /* The attachment itself. */
            $length = $this->_geti($data, 32);
            $attachment_data[0]['size']   = $length;
            $attachment_data[0]['stream'] = $this->_getx($data, $length);

            /* Checksum */
            $this->_geti($data, 16);
            break;

        case self::AMAPIATTRS:
            $value = $this->_getx($data, $this->_geti($data, 32));

            /* Checksum */
            $this->_geti($data, 16);
            $this->_extractMapiAttributes($value, $attachment_data);
            break;

        default:
            $this->_decodeAttribute($data, $attribute);
        }
    }
646447
protected static function parseData(array $rawData): array
    {
        $data = [];
        $tableName = null;
        $fieldCount = null;
        $idIndex = null;
        foreach ($rawData as $values) {
            if (!empty($values[0])) {
                // Skip comment lines, starting with "#"
                if ($values[0]{0} === '#') {
                    continue;
                }
                $tableName = $values[0];
                $fieldCount = null;
                $idIndex = null;
                if (!isset($data[$tableName])) {
                    $data[$tableName] = [];
                }
            } elseif (implode('', $values) === '') {
                $tableName = null;
                $fieldCount = null;
                $idIndex = null;
            } elseif ($tableName !== null && !empty($values[1])) {
                array_shift($values);
                if (!isset($data[$tableName]['fields'])) {
                    $data[$tableName]['fields'] = [];
                    foreach ($values as $value) {
                        if (empty($value)) {
                            continue;
                        }
                        $data[$tableName]['fields'][] = $value;
                        $fieldCount = count($data[$tableName]['fields']);
                    }
                    if (in_array('uid', $values)) {
                        $idIndex = array_search('uid', $values);
                        $data[$tableName]['idIndex'] = $idIndex;
                    }
                } else {
                    if (!isset($data[$tableName]['elements'])) {
                        $data[$tableName]['elements'] = [];
                    }
                    $values = array_slice($values, 0, $fieldCount);
                    foreach ($values as &$value) {
                        if ($value === '\\NULL') {
                            $value = null;
                        }
                    }
                    unset($value);
                    $element = array_combine($data[$tableName]['fields'], $values);
                    if ($idIndex !== null) {
                        $data[$tableName]['elements'][$values[$idIndex]] = $element;
                    } else {
                        $data[$tableName]['elements'][] = $element;
                    }
                }
            }
        }
        return $data;
    }
299512
public function parse($rawOutput)
    {
        if (!is_string($rawOutput)) {
            return false;
        }

        $rawOutput = trim($rawOutput);

        $this->rawOutput = $rawOutput;
        $this->decodedRawOutput = new DecodedRawOutput(trim($rawOutput));

        $exceptionFactory = new ExceptionFactory($rawOutput);

        if ($exceptionFactory->isInputFileNotFoundException()) {
            throw $exceptionFactory->createInputFileNotFoundException();
        }

        if ($exceptionFactory->isIncorrectNodeJsPathException()) {
            throw $exceptionFactory->createIncorrectNodeJsPathException();
        }

        if (!$this->decodedRawOutput->isWellFormed()) {
            throw new NodeJsLintOutputException(
                'Unexpected output; is not a lint result set',
                NodeJsLintOutputException::CODE_UNEXPECTED_OUTPUT
            );
        }

        $statusLine = $this->decodedRawOutput->getStatusLine();
        $entries = $this->decodedRawOutput->getLintResult();

        $this->nodeJsLintOutput = new NodeJslintOutput();
        $this->nodeJsLintOutput->setStatusLine($statusLine);

        if (empty($entries)) {
            return $this->nodeJsLintOutput;
        }

        $entryParser = new EntryFactory();

        foreach ($entries as $entryData) {
            if (!is_null($entryData)) {
                $this->nodeJsLintOutput->addEntry($entryParser->create($entryData));
            }
        }

        return $this->nodeJsLintOutput;
    }
413020
protected function parseTransactionAccountName()
    {
        $results = parent::parseTransactionAccountName();
        if ($results !== '') {
            return $results;
        }

        $results = [];
        if (preg_match('/:86:(GIRO|BGC\.)\s+[\d]+ (.+)/', $this->getCurrentTransactionData(), $results)
            && !empty($results[2])
        ) {
            return $this->sanitizeAccountName($results[2]);
        }

        if (preg_match('/:86:.+\n(.*)\n/', $this->getCurrentTransactionData(), $results)
            && !empty($results[1])
        ) {
            return $this->sanitizeAccountName($results[1]);
        }

        return '';
    }
182047
public static function fromString($rawRelation)
    {
        //name:assets;type:hasMany;params:App\\Models\\Asset|category_id|id,
        // expected string
        //name|type|params|field
        //assets|hasMany|App\\Models\\Asset,category_id,id|title

        $parts = explode(';', $rawRelation);
        $collection = [];
        foreach ($parts as $part) {
            if (!str_contains($part, ':')) {
                continue;
            }

            list($key, $value) = explode(':', $part);

            if ($key == 'params' || str_contains($value, '|')) {
                $value = explode('|', $value);
            }

            $collection[$key] = $value;
        }

        return self::get($collection);
    }
387582
public function factualize($rawData)
	{
		$rawdataSanitizer = $this->profile['rawdataSanitizer'];
		$validRawData = $rawdataSanitizer($rawData);
		$this->counter['entity']++;
		
		if (!empty($validRawData)){
			$datamapper = $this->profile['datamapper'];
			$dataCleaner = $this->profile['dataCleaner'];
			$factsErrorDetector = $this->profile['factsErrorDetector'];
			$data =$dataCleaner($datamapper($validRawData));
			$facts = call_user_func($this->modelClass.'::fromArray',$data,$this->profile['modelOptions']);
			$this->counter['triple'] += $facts->getTripleCount();
			if($error=$factsErrorDetector($facts)){
				$this->counter['error']++;
				throw new FactsValidatorWarning($error,$facts);
			}
		} else {
			$this->counter['insane']++;
			throw new InvalidRawDataWarning("Invalid rawdata",$rawData);
		}
		
		// ensure that not too many errors
		$errorRate = ($this->counter['error']/$this->counter['entity']);
		if(( $this->counter['entity'] > $this->profile['entityThreshold']) 
				&& ( $errorRate > $this->profile['resilienceToErrors'])){
			$x = $this->profile['resilienceToErrors']*100;
			throw new TooManyErrorsException("Error rate in data processing exceeded the $x% threshold");			
		}

		// ensure that not too many insaness raw data
		$insaneRate = ($this->counter['insane']/$this->counter['entity']);
		if(( $this->counter['entity'] > $this->profile['entityThreshold']) 
				&& ($insaneRate > $this->profile['resilienceToInsanes'])){
			$x = $this->profile['resilienceToInsanes']*100;
			throw new TooManyInsanesException("Unacceptable data rate exceeded the $x% threshold");			
		}

		return $facts;
	}
262458
public static Track2 from(final String rawTrackData)
  {
    final Matcher matcher = track2Pattern.matcher(trimToEmpty(rawTrackData));

    final String rawTrack2Data;
    final AccountNumber pan;
    final ExpirationDate expirationDate;
    final ServiceCode serviceCode;
    final String discretionaryData;

    if (matcher.matches())
    {
      rawTrack2Data = getGroup(matcher, 1);
      pan = new AccountNumber(getGroup(matcher, 2));
      expirationDate = new ExpirationDate(getGroup(matcher, 3));
      serviceCode = new ServiceCode(getGroup(matcher, 4));
      discretionaryData = getGroup(matcher, 5);
    }
    else
    {
      rawTrack2Data = null;
      pan = new AccountNumber();
      expirationDate = new ExpirationDate();
      serviceCode = new ServiceCode();
      discretionaryData = "";
    }

    return new Track2(rawTrack2Data,
                      pan,
                      expirationDate,
                      serviceCode,
                      discretionaryData);
  }
220167
public function parseData(): self
    {
        if (!is_array($this->raw_data)) {
            throw new RuntimeException('Response must be an array');
        }

        if (array_key_exists('quantity', $this->raw_data)) {
            $this->quantity = (int)$this->raw_data['quantity'];
        }

        if (array_key_exists('transaction_id', $this->raw_data)) {
            $this->transaction_id = $this->raw_data['transaction_id'];
        }

        if (array_key_exists('original_transaction_id', $this->raw_data)) {
            $this->original_transaction_id = $this->raw_data['original_transaction_id'];
        }

        if (array_key_exists('product_id', $this->raw_data)) {
            $this->product_id = $this->raw_data['product_id'];
        }

        if (array_key_exists('web_order_line_item_id', $this->raw_data)) {
            $this->web_order_line_item_id = $this->raw_data['web_order_line_item_id'];
        }

        if (array_key_exists('is_trial_period', $this->raw_data)) {
            $this->is_trial_period = filter_var($this->raw_data['is_trial_period'], FILTER_VALIDATE_BOOLEAN);
        }

        if (array_key_exists('is_in_intro_offer_period', $this->raw_data)) {
            $this->is_in_intro_offer_period = filter_var(
                $this->raw_data['is_in_intro_offer_period'],
                FILTER_VALIDATE_BOOLEAN
            );
        }

        if (array_key_exists('purchase_date_ms', $this->raw_data)) {
            $this->purchase_date = Carbon::createFromTimestampUTC(
                (int)round($this->raw_data['purchase_date_ms'] / 1000)
            );
        }

        if (array_key_exists('original_purchase_date_ms', $this->raw_data)) {
            $this->original_purchase_date = Carbon::createFromTimestampUTC(
                (int)round($this->raw_data['original_purchase_date_ms'] / 1000)
            );
        }

        if (array_key_exists('expires_date_ms', $this->raw_data)) {
            $this->expires_date = Carbon::createFromTimestampUTC((int)round($this->raw_data['expires_date_ms'] / 1000));
        } elseif (array_key_exists('expires_date', $this->raw_data) && is_numeric($this->raw_data['expires_date'])) {
            $this->expires_date = Carbon::createFromTimestampUTC(
                (int)round((int)$this->raw_data['expires_date'] / 1000)
            );
        }

        if (array_key_exists('cancellation_date_ms', $this->raw_data)) {
            $this->cancellation_date = Carbon::createFromTimestampUTC(
                (int)round($this->raw_data['cancellation_date_ms'] / 1000)
            );
        }

        return $this;
    }
639573
public static void decodeAndSetFileData(final File file, final String rawData) throws FrameworkException, IOException {

		Base64URIData uriData = new Base64URIData(rawData);
		setFileData(file, uriData.getBinaryData(), uriData.getContentType(), true);
	}
615993
public function getAccountData(\Flowpack\SingleSignOn\Server\Domain\Model\SsoClient $ssoClient, \TYPO3\Flow\Security\Account $account) {
		if ($this->configuration !== NULL) {
			$configuration = $this->configuration;
		} else {
			$configuration = $this->getDefaultConfiguration($ssoClient, $account);
		}
		$partyData = $this->transformValue($account->getParty(), $configuration['party']);
		$mappedRoles = array();
		foreach ($account->getRoles() as $role) {
			$mappedRoles[] = $role->getIdentifier();
		}
		return array(
			'accountIdentifier' => $account->getAccountIdentifier(),
			'roles' => $mappedRoles,
			'party' => $partyData
		);
	}