Skip to content

Commit

Permalink
feat(integrity): add .isIntegrity and .isIntegrityMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Apr 3, 2017
1 parent 17e9dd4 commit 1b29e6f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions index.js
Expand Up @@ -11,6 +11,7 @@ const STRICT_SRI_REGEX = /^([^-]+)-([A-Za-z0-9+/]+(?:=?=?))([?\x21-\x7E]*)$/
const VCHAR_REGEX = /^[\x21-\x7E]+$/

class IntegrityMetadata {
get isIntegrityMetadata () { return true }
constructor (metadata, opts) {
const strict = !!(opts && opts.strict)
this.source = metadata.trim()
Expand Down Expand Up @@ -65,6 +66,7 @@ class IntegrityMetadata {
}

class Integrity {
get isIntegrity () { return true }
toString (opts) {
opts = opts || {}
let sep = opts.sep || ' '
Expand Down
10 changes: 10 additions & 0 deletions test/integrity.js
Expand Up @@ -92,6 +92,16 @@ test('IntegrityMetadata.hexDigest()', t => {
t.done()
})

test('isIntegrity and isIntegrityMetadata', t => {
const sri = ssri.parse('sha512-bar')
t.ok(sri.isIntegrity, 'full sri has !!.isIntegrity')
t.ok(
sri['sha512'][0].isIntegrityMetadata,
'sri hash has !!.isIntegrityMetadata'
)
t.done()
})

test('semi-private', t => {
t.equal(ssri.Integrity, undefined, 'Integrity class is module-private.')
t.done()
Expand Down

0 comments on commit 1b29e6f

Please sign in to comment.