Python module to validate a CAP message against the OASIS CAP 1.2 schema and verify the XML signature.
Project description
The CAP Validator
The Python module for ensuring the validity of CAP alerts.
Features
- Schema Validation: Ensure your CAP XML file follows the CAP v1.2 standard.
- Digital Signature Validation: Verify that the CAP XML file comes from a legitimate source and has not been tampered with.
Note: Currently, only certificates issued by a trused certificate authority (CA) are supported. This means signatures with a self-signed certificate will not pass the validation.
Getting Started
1. Installation
pip install capvalidator
2A. Using the API
We can perform a total validation of the CAP XML file:
from capvalidator import validate_xml
# Read the CAP XML file as a byte string
with open(<cap-file-directory>, "rb") as f:
cap = f.read()
# Perform the validation
result = validate_xml(cap)
# Check the result
passed = result.passed
msg = result.msg
if not passed:
# Logic for handling invalid CAP file
# Logic for handling valid CAP file
Or, alternatively, a more refined validation:
from capvalidator import check_schema, check_signature
# Read the CAP XML file as a byte string
with open(<cap-file-directory>, "rb") as f:
cap = f.read()
# Validate the schema
schema_result = check_schema(cap)
# Check the results
passed = schema_result.passed
msg = schema_result.msg
if not passed:
# Logic for handling invalid CAP file
# Validate the signature
signature_result = check_signature(cap)
# Check the results
passed = signature_result.passed
msg = signature_result.msg
if not passed:
# Logic for handling invalid CAP file
# Logic for handling valid CAP file
There is also a date extractor which you may find useful:
from capvalidator import get_dates
# Read the CAP XML file as a byte string
with open(<cap-file-directory>, "rb") as f:
cap = f.read()
dts = get_dates(cap)
sent_date = dts.sent
effective_date = dts.effective
onset_date = dts.onset
expiry_date = dts.expiry
2B. Using the CLI
We can perform a total validation of the CAP XML file:
capvalidator validate <cap-file-directory>
Or, alternatively, more refined validations:
capvalidator validate --type schema <cap-file-directory>
capvalidator validate --type signature <cap-file-directory>
Bugs and Issues
All bugs, enhancements and issues are managed on GitHub.
Contact
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file capvalidator-0.1.0.dev2.tar.gz
.
File metadata
- Download URL: capvalidator-0.1.0.dev2.tar.gz
- Upload date:
- Size: 17.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c7e7ec89a15399994560fe7c11c1719e3c3e04b6dd6a1d21a0dde36010c0735 |
|
MD5 | 1d47120ae4643ea4b665721b3412835c |
|
BLAKE2b-256 | 23ed9bfec1e3434bfad0dfc9073ac6613eb8f5a4c6463504de8060e16cc2adb2 |
File details
Details for the file capvalidator-0.1.0.dev2-py3-none-any.whl
.
File metadata
- Download URL: capvalidator-0.1.0.dev2-py3-none-any.whl
- Upload date:
- Size: 15.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0b4429421a871346ac80a13a9a70fb6f5bd4480ac352ab04123cac05cee728f |
|
MD5 | 5d6bf4e4b23a04b54991defe64321f38 |
|
BLAKE2b-256 | a7c48105112853cbb02d0fe259b256fc7efc66978df8c699643b9f2d6060067a |