openfair/lib.rs
1/// OpenFAIR (Factor Analysis of Information Risk)
2/// The Open Group has created standards and best practices in the area of
3/// Security and Risk for 20+ years. The Open Group is a consensus-based
4/// and member-driven organization.
5/// Open FAIR provides a risk analysis methodology that describes the how and
6/// why of risk analysis. Open FAIR enhances higher level risk management
7/// frameworks from ISO, NIST, and other organizations by providing a means to
8/// more effectively analyse and measure risk. It improves consistency in
9/// undertaking analyses. The Open FAIR taxonomy and method provide the basis for
10/// meaningful metrics. It is flexible and can be used at different levels of
11/// abstraction to match the need, the available resources, and available data.
12/// The Open FAIR risk analysis method provides a more rigorous approach that
13/// helps to reduce gaps and analyst bias. It improves the ability to defend
14/// conclusions and recommendations.
15#[cfg(test)]
16mod tests;
17
18pub mod error;
19pub type Result<T> = std::result::Result<T, error::Error>;
20
21mod simulations;
22use self::simulations::{
23 charts::{model_set_to_d3js, scenario_to_d3js},
24 model::simulate_model,
25 scenario::simulate_scenario,
26};
27
28use serde_json::{json, Value};
29
30pub fn simulate(input_json: &Value) -> Result<Value> {
31 //! Simulate Scenarios and Model using the OpenFAIR
32 //! framework. Use the returned data with any charting tool
33 //!
34 //! # Example usage
35 //!```rust
36 //! use openfair::{simulate, Result};
37 //! use std::fs::read_to_string;
38 //!
39 //! fn main() -> Result<()> {
40 //!
41 //! let input = read_to_string("data/input.json")?;
42 //! let result = simulate(&serde_json::from_str(&input)?)?;
43 //!
44 //! println!("{:#?}", result);
45 //!
46 //! Ok(())
47 //! }
48 //! ```
49 Ok(json!({
50 "scenario": simulate_scenario(input_json)?,
51 "model": simulate_model(input_json)?,
52 }))
53}
54
55pub fn simulate_with_charts(input_json: &Value) -> Result<Value> {
56 //! Simulate Scenarios and Model using the OpenFAIR
57 //! framework, and return generated chart data that can be used with d3js
58 //!
59 //! # Example usage
60 //!```rust
61 //! use openfair::{simulate_with_charts, Result};
62 //! use std::fs::read_to_string;
63 //!
64 //! fn main() -> Result<()> {
65 //!
66 //! let input = read_to_string("data/input.json")?;
67 //! let result = simulate_with_charts(&serde_json::from_str(&input)?)?;
68 //!
69 //! println!("{:#?}", result);
70 //!
71 //! Ok(())
72 //! }
73 //! ```
74 let scenario_result = serde_json::to_string(&simulate_scenario(input_json)?)?;
75 let model_result = serde_json::to_string(&simulate_model(input_json)?)?;
76
77 Ok(json!({
78 "scenario": scenario_to_d3js(&scenario_result, vec!["risk", "v", "lef"])?,
79 "model": model_set_to_d3js(&model_result)?,
80 }))
81}