Skip to content

Add CustomHash class #229

Open
Open

Description

@bworrell

What do ya'll think about adding a CustomHash class which streamlines the creation of non-default hash types.

It could possibly derive from cybox.common.Hash but set the type_ field to an instance of cybox.common.String rather than cybox.common.VocabString (I'm not positive that'd work as planned).

It's not difficult to override the xsi:type, but it requires some in depth knoweldge of the data model and XML:

h = Hash("deadbeef", 'FOOHASH')
h.type_.xsi_type = None  # this is a bit tricky
print h.to_xml()

This yields:

<cyboxCommon:HashType
        xmlns:cyboxCommon="http://cybox.mitre.org/common-2"
        xmlns:cyboxVocabs="http://cybox.mitre.org/default_vocabularies-2"
        xmlns:example="http://example.com"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://cybox.mitre.org/common-2 http://cybox.mitre.org/XMLSchema/common/2.1/cybox_common.xsd http://cybox.mitre.org/default_vocabularies-2 http://cybox.mitre.org/XMLSchema/default_vocabularies/2.1/cybox_default_vocabularies.xsd">
    <cyboxCommon:Type>FOOHASH</cyboxCommon:Type>
    <cyboxCommon:Simple_Hash_Value>deadbeef</cyboxCommon:Simple_Hash_Value>
</cyboxCommon:HashType>
`h =  CustomHash('deadbeef', 'FOOHASH')  # automatically unsets the @xsi:type
print h.to_xml()

Activity

  1. gtback commented on Feb 25, 2015

    @gtback
    Contributor

    What about just adding a add_custom_hash() function to the HashList (and maybe types that use it, such as File)? I don't like adding more classes that aren't actual CybOX types (things like EmailAddress continually cause trouble).

  2. bworrell commented on Feb 25, 2015

    @bworrell
    ContributorAuthor

    Sure! I'm not married to the class-based approach and was mostly just brain dumping :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions