All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.brightsparklabs.asanti.model.data.RawAsnData Maven / Gradle / Ivy

The newest version!
/*
 * Maintained by brightSPARK Labs.
 * www.brightsparklabs.com
 *
 * Refer to LICENSE at repository root for license details.
 */

package com.brightsparklabs.asanti.model.data;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import java.util.Optional;
import java.util.regex.Pattern;

/**
 * Interface for modeling raw data (bytes) read from an ASN.1 binary file
 *
 * @author brightSPARK Labs
 */
public interface RawAsnData {
    // -------------------------------------------------------------------------
    // PUBLIC METHODS
    // -------------------------------------------------------------------------

    /**
     * Determines whether the specified tag is contained in the data
     *
     * @param tag tag to check
     * @return {@code true} if the tag is in the data; {@code false} otherwise
     */
    boolean contains(String tag);

    /**
     * Determines whether the data contains any tags matching the supplied regular expression
     *
     * @param regex regular expression to match tags against
     * @return {@code true} if the tag is in the data; {@code false} otherwise
     */
    boolean contains(Pattern regex);

    /**
     * Returns all tags found in the ASN data as a set of XPath like strings. The format of a singe
     * raw tag is index[tag] where index is oder within its parent that the tag was read in, and tag
     * is of the same format at an ASN.1 tag, so a context-specific tag of 2 is [2] and the implicit
     * tags for an Integer type is [UNIVERSAL 2].
     *
     * 

E.g. "/1[1]/1[UNIVERSAL 16]/1[4]", "3[0]/1[4]/2[1]", "/2[UNIVERSAL 17]/4[UNIVERSAL * 16]/0[UNIVERSAL 2]" * * @return all tags in the data */ ImmutableSet getRawTags(); /** * Returns the data (bytes) associated with the specified tag * * @param rawTag tag associated with the data * @return data associated with the specified tag or {@link Optional#empty()} if the tag does * not exist */ Optional getBytes(String rawTag); /** * Returns a mapping of all tags to the data (bytes) associated with them * *

E.g. "/0[1]/0[1]/0[1]" => "[0x00, 0x01]", "0[3]/1[1]/0[2]" => "[0x00, 0x01]" * * @return mapping of all tags to their associated data */ ImmutableMap getBytes(); /** * Returns the data (bytes) from all tags matching the supplied regular expression * *

E.g. * getBytesMatching(Pattern.compile("/0[1]/2[1]/.*")) => { "/0[1]/2[1]/0[1]" => * "[0x00, 0x01]", "/0[1]/2[1]/1[2]" => "[0x00, 0x01]" } * * @param regex regular expression to match tags against * @return data associated with the matching tags. Map is of form: {@code tag -> data} */ ImmutableMap getBytesMatching(Pattern regex); }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy