custom_codes/custom_codes.rs
1use serde::{Deserialize, Serialize};
2
3/// Give the Outcome of an operation
4/// ### Examples
5/// ```
6/// # use custom_codes::Outcome;
7/// let foo = Outcome::Success;
8/// assert_eq!(foo, Outcome::Success);
9/// ```
10#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
11pub enum Outcome {
12 ///Result of Operation completed successfully
13 Success,
14 /// Result of Operation produced an error
15 Failure,
16 /// The result of the operation was forwarded to another operation
17 Forward,
18}
19/// Give the Generic Outcome of an operation with custom result as a generic
20/// ### Examples
21/// ```
22/// # use custom_codes::GenericOutcome;
23/// let foo = GenericOutcome::Success("Foo");
24/// ```
25#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
26pub enum GenericOutcome<Reason> {
27 ///Result of Operation completed successfully
28 Success(Reason),
29 /// Result of Operation produced an error
30 Failure(Reason),
31 /// The result of the operation was forwarded to another operation
32 Forward(Reason),
33}
34/// Access status of token or access
35/// ### Examples
36/// ```
37/// # use custom_codes::AccessStatus;
38/// let foo = AccessStatus::Granted;
39/// assert_eq!(foo, AccessStatus::Granted);
40/// ```
41#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
42pub enum AccessStatus {
43 /// Process or User has been given a lease
44 Granted,
45 /// Token has been discarded
46 Revoked,
47 /// Access to token or session has expired
48 Expired,
49 /// Access has been denied
50 Denied,
51 /// The access token has been rejected because it is not authentic/genuine
52 Rejected,
53 /// Operation is being executed
54 InProgress,
55 /// Random Authentication Code (RAC) Token is genuine/authentic and therefore has been accepted
56 AccpetedRAC,
57 /// Random Authentication Code (RAC) Token is not genuine/authentic and therefore has been rejected
58 RejectedRAC,
59 /// Status of an operation is not initialized
60 Unspecified,
61}
62
63/// Creates a custom `boolean` value with more features than a Rustlang boolean which has only `true` or `false`
64/// ### Examples
65/// ```
66/// # use custom_codes::CustomBool;
67/// let foo = CustomBool::Unspecified;
68/// assert_eq!(foo, CustomBool::Unspecified);
69/// ```
70#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
71pub enum CustomBool {
72 /// Similar to boolean true
73 True,
74 /// Similar to boolean false
75 False,
76 /// Status of an operation is not initialized
77 Unspecified,
78}
79
80/// Custom Response Codes Using Enums For Efficient Comparison
81/// ### Examples
82/// ```
83/// # use custom_codes::DbOps;
84/// let foo = DbOps::Inserted;
85/// assert_eq!(foo, DbOps::Inserted);
86/// ```
87#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
88pub enum DbOps {
89 /// A Repository has been created
90 RepoCreated,
91 /// A Repository has been initialized by loading all contents of the repo
92 RepoInitialized,
93 /// The repository trying to be created already exists
94 RepoAlreadyExists,
95 /// An empty Repository with no databases
96 RepoEmpty,
97 /// An repository is not available on disk
98 RepoNotFound,
99 /// A Repository has been deleted
100 RepoDropped,
101 /// A checksum of the database shows a database is consistent
102 DbIntegrityConsistent,
103 /// A checksum fo the database shows the database is not consistent
104 DbIntegrityCorrupted,
105 /// A checksum of the document is consistent
106 DocumentIntegrityConsistent,
107 /// A checksum fo the document is not consistent
108 DocumentIntegrityCorrupted,
109 /// Database has been created
110 DbCreated,
111 /// Database has been Found after a search
112 DbFound,
113 /// Database being inserted already exists in the repo
114 DbAlreadyExists,
115 /// Database does not exist
116 DbNotFound,
117 /// Database is empty
118 DbEmpty,
119 /// A list containing Databases
120 DbList(Vec<String>),
121 /// A Database has neen modified
122 DbModified,
123 /// A database has been removed
124 DbDropped,
125 /// Document has been created
126 DocumentCreated,
127 /// Document has been inserted
128 DocumentInserted,
129 /// Document has been Found after a search
130 DocumentFound,
131 /// Document is empty
132 DocumentEmpty,
133 /// List of Documents
134 DocumentList(Vec<String>),
135 /// Document being inserted already exists in the DB
136 DocumentAlreadyExists,
137 /// Document does not exist
138 DocumentNotFound,
139 /// A Document has neen modified
140 DocumentModified,
141 /// Document has been removed
142 DocumentDropped,
143 /// Field has been created
144 FieldCreated,
145 /// Field has been inserted
146 FieldInserted,
147 /// Field has been Found after a search
148 FieldFound,
149 /// Field being inserted already exists in the DB
150 FieldAlreadyExists,
151 /// Field does not exist
152 FieldNotFound,
153 /// Contents of a field in heap allocated bytes
154 FieldContents(Vec<u8>),
155 /// List of fields in a document
156 FieldList(Vec<Vec<u8>>),
157 /// A Field has neen modified
158 FieldModified,
159 /// Field has been removed
160 FieldDropped,
161 /// A `Write` to create a database is successfull
162 Created,
163 /// A `Write` to a commit log was successful
164 Commited,
165 /// A `Write` to a commit log was unsuccessful
166 UnCommited,
167 /// A `Write` is successful
168 Inserted,
169 /// A `Change` is successful
170 Changed,
171 /// A `Change` is unsuccessful
172 Unchanged,
173 /// A `Command` is skipped since the document does not exist
174 Skipped,
175 /// Document already exists
176 AlreadyExists,
177 /// Document has been updated
178 Modified,
179 /// A document value has been `Swapped` replacing it with the new value provided
180 /// Especially useful for Key/Value stores
181 Swapped,
182 /// An Document has been deleted
183 Deleted,
184 /// Key Found in KV Store/Database, Field or Document depending on query
185 KeyFound,
186 /// Key Not Found in Database, Field or Document depending on query
187 KeyNotFound,
188 /// A Command or Query Has Not Been Executed
189 NotExecuted,
190 /// Two or more queries are not supposed to be used command eg. using `get` and `list` together
191 QueryConflictError,
192 /// Database is empty
193 Empty,
194 /// The command has been added to a queue
195 Queued,
196 /// Command has been removed from queue
197 DeQueued,
198 /// Log compaction successful
199 CompactionTrue,
200 /// Log compaction unsuccessful
201 CompactionFalse,
202 /// Connection to a database is not available
203 ConnRefused,
204 /// Port is in use
205 PortAddrInUse,
206 /// Driver to the database has an error
207 DriverError,
208 /// An error occured when trying to execute a command at database level
209 RuntimeError,
210 /// Encountered Errors When Trying to connect to a database
211 EncounteredErrors(String),
212 /// No permissions to complete the I/O operation
213 PermissionDenied,
214 /// A cluster in online and ready to receive commands
215 ClusterOnline,
216 /// A cluster is offline
217 ClusterOffline,
218 /// Cluster details synced across all nodes
219 ClusterSynced,
220 /// Added a node to the cluster
221 ClusterNodeAdded,
222 /// Updated configuration to the cluster
223 ConfigUpdated,
224 /// A node has been permanently removed
225 ClusterNodeDropped,
226 /// The details have been inserted to the specified logs
227 Logged,
228 /// The details have not been logged
229 NotLogged,
230 /// The Operation was interrupted and can be resumed
231 Interrupted,
232 /// Status of an operation is not initialized
233 Unspecified,
234}
235
236/// Command Operations for execution
237/// ### Examples
238/// ```
239/// # use custom_codes::ExecCommand;
240/// let foo = ExecCommand::Queued;
241/// assert_eq!(foo, ExecCommand::Queued);
242/// ```
243#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
244pub enum ExecCommand {
245 /// Command Operation added to Queue
246 Queued,
247 /// Command removed from queue
248 DeQueued,
249 /// Command in progress
250 InProgress,
251 /// Command paused
252 Paused,
253 /// Command suspended but not killed
254 Frozen,
255 /// Command killed and removed from execution stack
256 Killed,
257 /// Command has finished execution
258 Executed,
259 /// The Operation was interrupted and can be resumed
260 Interrupted,
261 /// Status of an operation is not initialized
262 Unspecified,
263}
264
265/// File operations
266/// ### Examples
267/// ```
268/// # use custom_codes::FileOps;
269/// let foo = FileOps::DirAccessDenied;
270/// assert_eq!(foo, FileOps::DirAccessDenied);
271/// ```
272#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
273pub enum FileOps {
274 /// Directory Created
275 DirCreated,
276 /// Directory Access Denied
277 DirAccessDenied,
278 /// Directory is read only
279 DirIsReadOnly,
280 /// Directory is append only
281 DirectoryAppendOnly,
282 /// File is read only
283 FileIsReadOnly,
284 /// File is append only
285 FileIsAppendOnly,
286 /// Delete operation denied due to permissions
287 DeletionDenied,
288 /// Deletion could not be done as another operation is reading the file
289 DeletionToBeDone,
290 /// Read has been completed especially useful in `async` operations
291 ReadDone,
292 /// Write operation has been competed
293 WriteDone,
294 /// The file or directory already exists
295 AlreadyExists,
296 /// Update operation completed
297 UpdateDone,
298 /// Deletion operation completed
299 DeletionDone,
300 /// Read is in progress
301 ReadInProgress,
302 /// Write is in progress
303 WriteInProgess,
304 /// Update is in progress
305 UpdateInProgress,
306 /// File has been deleted
307 DeletionInProgress,
308 /// Directory has been opened
309 DirOpened,
310 /// Directory is no longer open
311 DirClosed,
312 /// Directory has been modified
313 DirModified,
314 /// File has been opened
315 OpenedFile,
316 /// File has been closed
317 ClosedFile,
318 /// Unable To Open File
319 OpenError,
320 /// The operation comleted with a given error
321 EncounteredErrors(String),
322 /// Creation of the file is denied
323 CreateDenied,
324 /// Read acess to file is denied
325 ReadDenied,
326 /// Update to the file is denied
327 UpdateDenied,
328 /// Writing to the file has been denied
329 WriteDenied,
330 /// Appending to the file has been denied
331 AppendDenied,
332 /// Metadata has been added to file or directory
333 MetadataAdded,
334 /// File or directory does not contain Metadata
335 MetadataNotAvailable,
336 /// metadata changed
337 MetadataChanged,
338 /// Netadata has been Deleted
339 MetadataDeleted,
340 /// Open a file. any open can read contents
341 OpenTrue,
342 /// Do not open file
343 OpenFalse,
344 /// Create a file if it does not exist
345 CreateTrue,
346 /// Do Not Create a file it does not exist
347 CreateFalse,
348 /// Write to a file
349 WriteTrue,
350 /// Do not write to file
351 WriteFalse,
352 /// Append to a file
353 AppendTrue,
354 /// The Operation was interrupted and can be resumed
355 Interrupted,
356 /// Delete a file if it exists,
357 DeleteTrue,
358}
359
360/// Compression of files, bytes or directories
361/// ### Examples
362/// ```
363/// # use custom_codes::Compression;
364/// let foo = Compression::Done;
365/// assert_eq!(foo, Compression::Done);
366/// ```
367#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
368pub enum Compression {
369 /// Compression done
370 Done,
371 /// Compression in progress
372 InProgress,
373 /// Compression already done
374 AlreadyCompressed,
375 /// Compression is not possible
376 Impossible,
377 /// A process is writing to the file being compressed
378 ToBeDone,
379 /// Streaming and compressing at the same time
380 StreamCompress,
381 /// The Operation was interrupted and can be resumed
382 Interrupted,
383 /// Status of an operation is not initialized
384 Unspecified,
385}
386
387/// Status of a subscription that happens over a timespec
388/// ### Examples
389/// ```
390/// # use custom_codes::Subscription;
391/// let foo = Subscription::Subscribed;
392/// assert_eq!(foo, Subscription::Subscribed);
393/// ```
394#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
395pub enum Subscription {
396 /// Subscription is active
397 Subscribed,
398 /// Subscription is inactive
399 Unsubscribed,
400 /// Subscription is not yet activated
401 NotActivated,
402 /// Status of an operation is not initialized
403 Unspecified,
404}
405
406/// Status of an activity
407/// ### Examples
408/// ```
409/// # use custom_codes::ActivityStatus;
410/// let foo = ActivityStatus::Activated;
411/// assert_eq!(foo, ActivityStatus::Activated);
412/// ```
413#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
414pub enum ActivityStatus {
415 /// Status of an operation has been started
416 Activated,
417 /// Status of an operation has been stopped
418 Deactivated,
419 /// Status of an operation is not initialized
420 Unspecified,
421}
422/// Initialize an activity
423/// ### Examples
424/// ```
425/// # use custom_codes::ActivityToggle;
426/// let foo = ActivityToggle::Activate;
427/// assert_eq!(foo, ActivityToggle::Activate);
428/// ```
429#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
430pub enum ActivityToggle {
431 /// Activate an operation
432 Activate,
433 /// Deactivate an operation
434 Deactivate,
435 /// Status of an operation is not initialized
436 Unspecified,
437}
438/// Command Line Options
439/// ### Examples
440/// ```
441/// # use custom_codes::Cli;
442/// let foo = Cli::ParseInProgress;
443/// assert_eq!(foo, Cli::ParseInProgress);
444/// ```
445#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
446pub enum Cli {
447 /// Parsing
448 ParseInProgress,
449 /// Parsed Arguments
450 ParseArgs,
451 /// Parsing Argument field in progress
452 ArgFieldParseInPorgress,
453 /// Parsed Argument field
454 ParsedArgField,
455 /// Parsing Asynchronously
456 ParseAsync,
457 /// Parsing field Asynchronously
458 ArgFieldAsyncParseInPorgress,
459 /// Not enough commandline arguments
460 NotEnoughArgs,
461 /// Encountered parsing errors
462 EncounteredErrors(String),
463}
464/// Date and time custom codes
465/// ### Examples
466/// ```
467/// # use custom_codes::DateTimeOp;
468/// let foo = DateTimeOp::DateCreated;
469/// assert_eq!(foo, DateTimeOp::DateCreated);
470/// ```
471#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
472pub enum DateTimeOp {
473 /// Date created
474 DateCreated,
475 /// Date deleted
476 DateDeleted,
477 /// Date Modified
478 DateModified,
479 /// Date period not specified
480 DateUnspecified,
481 /// Date created
482 TimeCreated,
483 /// Date deleted
484 TimeDeleted,
485 /// Date Modified
486 TimeModified,
487 /// Time period not specified
488 TimeUnspecified,
489 /// Both date and time not specied
490 DateTimeUnspecified,
491}
492
493/// Security operations on encryption and keys
494/// ### Examples
495/// ```
496/// # use custom_codes::SecOps;
497/// let foo = SecOps::KeyCorrupted;
498/// assert_eq!(foo, SecOps::KeyCorrupted);
499/// ```
500#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
501pub enum SecOps {
502 /// Key could not be verified as it did not finish streaming
503 KeyCorrupted,
504 /// Key Authentic and approved
505 KeyAuthentic,
506 /// Key has been tampered with
507 KeyInvalid,
508 /// Timed Out while verification was in progress
509 TimedOut,
510 /// Possible Identity Forgery
511 PossibleIdTheft,
512 /// Data encrypted has been corrupted
513 DataCorrupted,
514 /// Data has been tampered with
515 DataInvalid,
516 /// Data has been encrypted
517 Encrypted,
518 /// Key generation successful,
519 KeyGenSucceded,
520 /// Key generation failed
521 KeyGenFailed,
522 /// Key has been deleted
523 KeyDeleted,
524 /// random data generated from Cryptographically Secure PRNG (CSPRNG)
525 CryptoRandomGenerated,
526 /// random data generated from Cryptographically Secure PRNG (CSPRNG) was not generated successfully
527 CryptoRandomGenFailure,
528 /// random data generated from Noncryptographic PRNG
529 NonCryptoRandomGenerated,
530 /// random data generated from Noncryptographic PRNG was not generated successfully
531 NonCryptoRandomGenFailure,
532 /// Message Authentication Code is authentic
533 AuthenticMAC,
534 /// Message Authentication Code is corrupted
535 InvalidMAC,
536 /// Random Authentication Code (RAC) Token is genuine/authentic
537 ValidRAC,
538 /// Random Authentication Code (RAC) Token is not genuine/authentic
539 InvalidRAC,
540 /// Key Length is equal to the length needed by the cryptography algorithm
541 KeyLengthSane,
542 /// Key length too short
543 KeyTooShort(KeyLength),
544 /// Key Length is too long
545 KeyTooLong(KeyLength),
546}
547
548impl std::fmt::Display for SecOps {
549 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
550 match self {
551 SecOps::KeyCorrupted => write!(f, "Key could not be verified as it did not finish streaming"),
552 SecOps::KeyAuthentic => write!(f, "Key Authentic and approved"),
553 SecOps::KeyInvalid => write!(f, "Key has been tampered with"),
554 SecOps::TimedOut => write!(f, "Timed Out while verification was in progress"),
555 SecOps::PossibleIdTheft => write!(f, "Possible Identity Forgery"),
556 SecOps::DataCorrupted => write!(f, "Data encrypted has been corrupted"),
557 SecOps::DataInvalid => write!(f, "Data has been tampered with"),
558 SecOps::Encrypted => write!(f, "Data has been encrypted"),
559 SecOps::KeyGenSucceded => write!(f, "Key generation successful"),
560 SecOps::KeyGenFailed => write!(f, "Key generation failed"),
561 SecOps::KeyDeleted => write!(f, "Key has been deleted"),
562 SecOps::CryptoRandomGenerated => write!(f, "random data generated from Cryptographically Secure PRNG (CSPRNG)"),
563 SecOps::CryptoRandomGenFailure => write!(f, "random data generated from Cryptographically Secure PRNG (CSPRNG) was not generated"),
564 SecOps::NonCryptoRandomGenerated => write!(f, "random data generated from Noncryptographic PRNG"),
565 SecOps::NonCryptoRandomGenFailure => write!(f, "random data generated from Noncryptographic PRNG was not generated"),
566 SecOps::AuthenticMAC => write!(f, "Message Authentication Code is authentic"),
567 SecOps::InvalidMAC => write!(f, "Message Authentication Code is corrupted"),
568 SecOps::ValidRAC => write!(f, "Random Authentication Code (RAC) Token is genuine/authentic"),
569 SecOps::InvalidRAC => write!(f, "Random Authentication Code (RAC) Token is not genuine/authentic"),
570 SecOps::KeyLengthSane => write!(f, "Key Length is equal to the length needed by the cryptography algorithm"),
571 SecOps::KeyTooShort(_) => write!(f, "Key length too short"),
572 SecOps::KeyTooLong(_) => write!(f, "Key Length is too long"),
573 }
574 }
575}
576
577impl std::error::Error for SecOps {
578 fn description(&self) -> &str {
579 match self {
580 SecOps::KeyCorrupted => "Key could not be verified as it did not finish streaming",
581 SecOps::KeyAuthentic => "Key Authentic and approved",
582 SecOps::KeyInvalid => "Key has been tampered with",
583 SecOps::TimedOut => "Timed Out while verification was in progress",
584 SecOps::PossibleIdTheft => "Possible Identity Forgery",
585 SecOps::DataCorrupted => "Data encrypted has been corrupted",
586 SecOps::DataInvalid => "Data has been tampered with",
587 SecOps::Encrypted => "Data has been encrypted",
588 SecOps::KeyGenSucceded => "Key generation successful",
589 SecOps::KeyGenFailed => "Key generation failed",
590 SecOps::KeyDeleted => "Key has been deleted",
591 SecOps::CryptoRandomGenerated => "random data generated from Cryptographically Secure PRNG (CSPRNG)",
592 SecOps::CryptoRandomGenFailure => "random data generated from Cryptographically Secure PRNG (CSPRNG) was not generated",
593 SecOps::NonCryptoRandomGenerated => "random data generated from Noncryptographic PRNG",
594 SecOps::NonCryptoRandomGenFailure => "random data generated from Noncryptographic PRNG was not generated",
595 SecOps::AuthenticMAC => "Message Authentication Code is authentic",
596 SecOps::InvalidMAC => "Message Authentication Code is corrupted",
597 SecOps::ValidRAC => "Random Authentication Code (RAC) Token is genuine/authentic",
598 SecOps::InvalidRAC => "Random Authentication Code (RAC) Token is not genuine/authentic",
599 SecOps::KeyLengthSane => "Key Length is equal to the length needed by the cryptography algorithm",
600 SecOps::KeyTooShort(_) => "Key length too short",
601 SecOps::KeyTooLong(_) => "Key Length is too long",
602 }
603 }
604
605 fn cause(&self) -> Option<&dyn std::error::Error> {
606 match self {
607 SecOps::KeyCorrupted => Some(&SecOps::KeyCorrupted),
608 SecOps::KeyAuthentic => Some(&SecOps::KeyAuthentic),
609 SecOps::KeyInvalid => Some(&SecOps::KeyInvalid),
610 SecOps::TimedOut => Some(&SecOps::TimedOut),
611 SecOps::PossibleIdTheft => Some(&SecOps::PossibleIdTheft),
612 SecOps::DataCorrupted => Some(&SecOps::DataCorrupted),
613 SecOps::DataInvalid => Some(&SecOps::DataInvalid),
614 SecOps::Encrypted => Some(&SecOps::Encrypted),
615 SecOps::KeyGenSucceded => Some(&SecOps::KeyGenSucceded),
616 SecOps::KeyGenFailed => Some(&SecOps::KeyGenFailed),
617 SecOps::KeyDeleted => Some(&SecOps::KeyDeleted),
618 SecOps::CryptoRandomGenerated => Some(&SecOps::CryptoRandomGenerated),
619 SecOps::CryptoRandomGenFailure => Some(&SecOps::CryptoRandomGenFailure),
620 SecOps::NonCryptoRandomGenerated => Some(&SecOps::NonCryptoRandomGenFailure),
621 SecOps::NonCryptoRandomGenFailure => Some(&SecOps::NonCryptoRandomGenFailure),
622 SecOps::AuthenticMAC => Some(&SecOps::AuthenticMAC),
623 SecOps::InvalidMAC => Some(&SecOps::InvalidMAC),
624 SecOps::ValidRAC => Some(&SecOps::ValidRAC),
625 SecOps::InvalidRAC => Some(&SecOps::InvalidRAC),
626 SecOps::KeyLengthSane => Some(&SecOps::KeyLengthSane),
627 SecOps::KeyTooShort(ref length) => length.source(),
628 SecOps::KeyTooLong(ref length) => length.source(),
629 }
630 }
631}
632
633/// The length of a key in bytes needed by a cryptography algorithm
634/// ### Examples
635/// ```
636/// # use custom_codes::KeyLength;
637/// let foo = KeyLength::Bytes32;
638/// assert_eq!(foo, KeyLength::Bytes32);
639/// ```
640#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
641pub enum KeyLength {
642 /// A Key length of 8 bytes
643 Bytes8,
644 /// A Key length of 16 bytes
645 Bytes16,
646 /// A Key length of 24 bytes
647 Bytes24,
648 /// A Key length of 32 bytes
649 Bytes32,
650 /// A Key length of 64 bytes
651 Bytes64,
652 /// A Key length of 128 bytes
653 Bytes128,
654 /// A Key length of 256 bytes
655 Bytes256,
656 /// A Key length of 512 bytes
657 Bytes512,
658 /// A Key length of 1024 bytes
659 Bytes1024,
660 /// A Key length of 2048 bytes
661 Bytes2048,
662 /// A Key length of 4096 bytes
663 Bytes4096,
664}
665
666impl std::fmt::Display for KeyLength {
667 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
668 match self {
669 KeyLength::Bytes8 => write!(f, "KeyLength::Bytes8"),
670 KeyLength::Bytes16 => write!(f, "KeyLength::Bytes16"),
671 KeyLength::Bytes24 => write!(f, "KeyLength::Bytes24"),
672 KeyLength::Bytes32 => write!(f, "KeyLength::Bytes32"),
673 KeyLength::Bytes64 => write!(f, "KeyLength::Bytes64"),
674 KeyLength::Bytes128 => write!(f, "KeyLength::Bytes128"),
675 KeyLength::Bytes256 => write!(f, "KeyLength::Bytes256"),
676 KeyLength::Bytes512 => write!(f, "KeyLength::Bytes512"),
677 KeyLength::Bytes1024 => write!(f, "KeyLength::Bytes1024"),
678 KeyLength::Bytes2048 => write!(f, "KeyLength::Bytes2048"),
679 KeyLength::Bytes4096 => write!(f, "KeyLength::Bytes4096"),
680 }
681 }
682}
683
684impl std::error::Error for KeyLength {
685 fn description(&self) -> &str {
686 match self {
687 KeyLength::Bytes8 => "The key is not 8 bytes in length",
688 KeyLength::Bytes16 => "The key is not 16 bytes in length",
689 KeyLength::Bytes24 => "The key is not 24 bytes in length",
690 KeyLength::Bytes32 => "The key is not 32 bytes in length",
691 KeyLength::Bytes64 => "The key is not 64 bytes in length",
692 KeyLength::Bytes128 => "The key is not 128 bytes in length",
693 KeyLength::Bytes256 => "The key is not 256 bytes in length",
694 KeyLength::Bytes512 => "The key is not 512 bytes in length",
695 KeyLength::Bytes1024 => "The key is not 1024 bytes in length",
696 KeyLength::Bytes2048 => "The key is not 2048 bytes in length",
697 KeyLength::Bytes4096 => "The key is not 4096 bytes in length",
698 }
699 }
700
701 fn cause(&self) -> Option<&dyn std::error::Error> {
702 match self {
703 KeyLength::Bytes8 => Some(&KeyLength::Bytes8),
704 KeyLength::Bytes16 => Some(&KeyLength::Bytes16),
705 KeyLength::Bytes24 => Some(&KeyLength::Bytes24),
706 KeyLength::Bytes32 => Some(&KeyLength::Bytes32),
707 KeyLength::Bytes64 => Some(&KeyLength::Bytes64),
708 KeyLength::Bytes128 => Some(&KeyLength::Bytes128),
709 KeyLength::Bytes256 => Some(&KeyLength::Bytes256),
710 KeyLength::Bytes512 => Some(&KeyLength::Bytes512),
711 KeyLength::Bytes1024 => Some(&KeyLength::Bytes1024),
712 KeyLength::Bytes2048 => Some(&KeyLength::Bytes2048),
713 KeyLength::Bytes4096 => Some(&KeyLength::Bytes4096),
714 }
715 }
716}
717
718/// Hardware Resources of a physical computer
719/// ### Examples
720/// ```
721/// # use custom_codes::HardwareResources;
722/// let foo = HardwareResources::CpuMaxed;
723/// assert_eq!(foo, HardwareResources::CpuMaxed);
724/// ```
725#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
726pub enum HardwareResources {
727 /// CPU is under heavy load
728 CpuUnderHeavyLoad,
729 /// RAM is under heavy load
730 RamUnderHeavyLoad,
731 /// CPU is maxed out
732 CpuMaxed,
733 /// CPU is Overclocked
734 CpuOverclocked,
735 /// CPU is underclocked eg. to save power
736 CpuUnderclocked,
737 /// Cpu is idle
738 CpuIdle,
739 /// CPU heat is normal
740 CpuTempOk,
741 /// CPU heat is high
742 CpuThrottling,
743 /// Etherned Card Available for use
744 EthernetDevUp,
745 ///Ethernet is unavailavle for use
746 EthernetDevDown,
747 /// Ethernet card accessed by processed
748 EthernetDevAccessed,
749 /// Carrier chip available
750 CarrierDevUp,
751 /// Carrier chip unavailable
752 CarrierDevDown,
753 /// Carrier chip does not exist in hardware
754 CarrierDevChipMissing,
755 ///Drivers are missing for components listed
756 DriverMissing,
757 ///Camera or optical module available
758 OpticDevUp,
759 ///Camera or optical module unavailable
760 OpticDevDown,
761 ///Camera or optical module accessed
762 OpticalDevAccessed,
763 ///Camera or optical module access is denied
764 OpticalDevAccessDenied,
765 /// Camera or optical module powered off
766 OpticalDevPoweredOff,
767 /// Optical chip does not exist in hardware
768 OticalDevChipMissing,
769 /// NFC device is available
770 NfcDevUp,
771 /// NFC device is unavailable
772 NfcDevDown,
773 /// NFC device is active
774 NfcDevActive,
775 /// NFC device is paired to other device
776 NfcDevPaired,
777 /// NFC device is accessed
778 NfcDevAccessed,
779 /// NFC device access is denied
780 NfcDevDenied,
781 /// NFC device is closed
782 NfcDevClosed,
783 /// NFC device is powered of
784 NfcDevPoweredOff,
785 /// WiFi module avaliable
786 WiFiDevUp,
787 /// WiFi module unavaliable
788 WiFiDevDown,
789 /// WiFi module access is denied,
790 WiFiDevAccessDenied,
791 /// WiFi module powered off
792 WiFiDevPoweredOff,
793 /// WiFi has been accessed by process
794 WiFiDevAccessed,
795 /// WiFi is in hotspot mode
796 WiFiDevHotSpotMode,
797 /// Bluetooth is available
798 BluetoothDevUp,
799 /// Bluetooth is paired
800 BluetoothDevPaired,
801 /// Bluetooth device is trusted
802 BluetoothDevDevTrusted,
803 /// Bluetooth has been untrusted
804 BluetoothDevDevUntrusted,
805 /// Bluetooth access is denied
806 BluetoothDevAccessDenied,
807 /// Bluetooth device has been unpaired
808 BluetoothDevUnpaired,
809 /// Bluetooth is in share mode for data
810 BluetoothDevShareMode,
811 /// Bluetooth is in audio or data sink
812 BluetoothDevSinkMode,
813 /// Bluetooth is transmitting
814 BluetoothDevTxMode,
815 /// Bluetooth is Receiving
816 BluetoothDevRxMode,
817 /// Bluetooth is closed
818 BluetoothDevClosed,
819 /// Bluetooth is powered off
820 BluetoothDevPowerOff,
821 /// Bluetooth is unavailable
822 BluetoothDevDown,
823 /// USB controller is available
824 UsbDevUp,
825 /// USB controller is available
826 UsbDevDown,
827 /// USB controller is powered off
828 UsbDevPoweredOff,
829 /// USB device has been added
830 UsbDevAdded,
831 /// USB is transmitting
832 UsbDevTxMode,
833 /// USB is recieving
834 UsbDevRxMode,
835 /// USB device has been removed
836 UsbDevRemoved,
837 /// USB device access is denied
838 UsbDevAccessDenied,
839 /// GPS module available
840 GpsDevUp,
841 /// GPS module unavailable
842 GpsDevDown,
843 /// GPS is transmitting
844 GpsDevTxMode,
845 /// GPS module receiving
846 GpsDevRxmode,
847 /// GPS Device access denied
848 GpsDevAccessDenied,
849 /// The device is in airplane mode
850 AirplaneMode,
851 /// Hardware not specified
852 Unspecified,
853}
854
855/// Networking Specific
856/// ### Examples
857/// ```
858/// # use custom_codes::Networking;
859/// let foo = Networking::NetworkAccessDenied;
860/// assert_eq!(foo, Networking::NetworkAccessDenied);
861/// ```
862#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
863pub enum Networking {
864 /// Permission to access network is denied
865 NetworkAccessDenied,
866 /// Network is available but unable to reach destination host
867 HostUnreachable,
868 /// Connection was reset and has been terminated
869 ConnectionReset,
870 /// Connection to the address has been stopped
871 ConnectionAborted,
872 /// The network operation failed because process has not finished connecting
873 NotConnected,
874 /// Headers for a particular protocol corrupted
875 HeadersCorrupted,
876 /// Server access was reached but didnt respond
877 ServerNotResponding,
878 /// IP Address is already in use
879 IpInUse,
880 /// Port is in use but IP is available
881 PortInUse,
882 /// The IP address and Port are both in use
883 AddrInUse,
884 /// IP Address is available
885 IpAvailable,
886 /// Network Operation Failed because a pipe is broken
887 BrokenPipe,
888 /// Connection already exists
889 NetConnExists,
890 /// Operation parameters are Invalid
891 InvalidNetInput,
892 /// Operation parameters are fine but operation data is invalid
893 InvalidNetData,
894 /// The network operation timed out
895 NetTimedOut,
896 /// The Network Operation was interrupted and can be resumed
897 Interrupted,
898 /// Unexpected end of connection
899 UnexpectedNetEof,
900 /// Connection Driver is buggy
901 NetDriverBuggy,
902 /// Network Unspecified
903 Unspecified,
904}
905
906/// Hardware security access
907/// ### Examples
908/// ```
909/// # use custom_codes::SecHardware;
910/// let foo = SecHardware::UsbKeyUp;
911/// assert_eq!(foo, SecHardware::UsbKeyUp);
912/// ```
913#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
914pub enum SecHardware {
915 /// USB Stick Hardware Key is available
916 UsbKeyUp,
917 /// USB Stick Hardware Key is unavailable
918 UsbKeyDown,
919 /// USB Stick Hardware Key is transmitting,
920 UsbKeyDevTxMode,
921 /// For receiving updates and is not avaiable for use
922 UsbKeyDevRxMode,
923 /// Device access denied
924 UsbKeyDevAccessDenied,
925 /// Fingerprint device is available
926 FingerPrintDevUp,
927 /// Fingerprint device is unavailable
928 FingerPrintDevDown,
929 /// Fingerprint device is powered of
930 FingerPrintDevPoweredOff,
931 /// Fingerprint device is transmitting
932 FingerPrintDevTxMode,
933 /// For receiving updates and is not avaiable for use
934 FingerPrintDevRxMode,
935 /// Fingerprint Device access denied
936 FingerPrintDevAccessDenied,
937 /// Iris scanner is available
938 IrisDevUp,
939 /// Iris scanner is unavailable
940 IrisDevDown,
941 /// Iris scanner is powered off
942 IrisDevPoweredOff,
943 /// Iris scanner is transmitting
944 IrisDevTxMode,
945 /// For receiving updates and is not avaiable for use
946 IrisDevRxMode,
947 /// Iris Scanner Device access denied
948 IrisDevAccessDenied,
949 /// Infra-red device is available
950 IrFloodDevUp,
951 /// Infra-red device is unavailable
952 IrFloodDevDown,
953 /// Infra-red device is powered off
954 IrFloodDevPoweredOff,
955 /// Infra-red device is transmitting
956 IrDevTxMode,
957 /// For receiving updates and is not avaiable for use
958 IrDevRxMode,
959 /// Infra-red Device access denied
960 IrDevAccessDenied,
961 /// Hardware Unspecified
962 Unspecified,
963}