Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CustomHash class #229

Open
bworrell opened this issue Feb 17, 2015 · 2 comments
Open

Add CustomHash class #229

bworrell opened this issue Feb 17, 2015 · 2 comments

Comments

@bworrell
Copy link
Contributor

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()
@gtback
Copy link
Contributor

gtback commented Feb 25, 2015

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).

@bworrell
Copy link
Contributor Author

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants