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 derives for Clone, Debug, Eq, Hash, and PartialEq for public types #119

Merged
merged 11 commits into from Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,11 @@
# Changelog

## 0.20.0

- [[#119](https://github.com/IronCoreLabs/ironoxide/pull/119)]
- Add `Clone`, `Debug`, `Eq`, `Hash`, and `PartialEq` to almost all public structs.
- Depend on a specific commit hash of itertools

## 0.19.1

- [[#120](https://github.com/IronCoreLabs/ironoxide/pull/120)]
Expand Down
7 changes: 4 additions & 3 deletions Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "ironoxide"
version = "0.19.1"
version = "0.20.0"
authors = ["IronCore Labs <info@ironcorelabs.com>"]
readme = "README.md"
license = "AGPL-3.0-only"
Expand All @@ -24,11 +24,12 @@ rand = "~0.6"
rand_chacha = "~0.1"
regex = "~1.3"
ring = { version= "~0.16", features = ["std"] }
recrypt = "~0.9.2"
recrypt = "~0.10"
url= "~2.1.0"
reqwest = {version="~0.10.0", features = ["json"]}
hex = "~0.3"
itertools = "~0.8"
# itertools 0.8.2++ - remove on next release
itertools = {git = "https://github.com/rust-itertools/itertools", rev = "c83cc48ffe39b96b7c6797b7b31752e840b373bb"}
futures = "~0.3.1"
quick-error = "~1.2"
lazy_static = "~1.4"
Expand Down
1 change: 0 additions & 1 deletion build.rs
@@ -1,4 +1,3 @@
extern crate protobuf_codegen_pure;
use std::{
env,
fs::File,
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/aes.rs
Expand Up @@ -83,7 +83,7 @@ impl EncryptedMasterKey {
dest
}
}
#[derive(Debug, Clone)]
#[derive(Clone, Debug)]
pub struct AesEncryptedValue {
aes_iv: [u8; AES_IV_LEN],
ciphertext: Vec<u8>,
Expand Down
4 changes: 2 additions & 2 deletions src/document/mod.rs
Expand Up @@ -20,16 +20,16 @@ use itertools::{Either, EitherOrBoth, Itertools};
pub mod advanced;

/// Optional parameters that can be provided when encrypting a new document.
#[derive(Debug, PartialEq, Clone)]
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct DocumentEncryptOpts {
id: Option<DocumentId>,
name: Option<DocumentName>,
// at least one user/group must be included either explicitly or via a policy
grants: EitherOrBoth<ExplicitGrant, PolicyGrant>,
}
#[derive(Debug, PartialEq, Clone)]

/// Explicit users/groups that should have access to decrypt a document.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct ExplicitGrant {
grant_to_author: bool,
grants: Vec<UserOrGroup>,
Expand Down
2 changes: 1 addition & 1 deletion src/group.rs
Expand Up @@ -11,8 +11,8 @@ use crate::{
};
use vec1::Vec1;

#[derive(Clone)]
/// Options for group creation.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct GroupCreateOpts {
// unique id of a group within a segment. If none, the server will assign an id.
id: Option<GroupId>,
Expand Down
38 changes: 19 additions & 19 deletions src/internal/document_api/mod.rs
Expand Up @@ -46,7 +46,7 @@ const HEADER_META_LENGTH_LENGTH: usize = 2;
const CURRENT_DOCUMENT_ID_VERSION: u8 = 2;

/// Document ID. Unique within the segment. Must match the regex `^[a-zA-Z0-9_.$#|@/:;=+'-]+$`
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct DocumentId(pub(crate) String);
impl DocumentId {
pub fn id(&self) -> &str {
Expand Down Expand Up @@ -74,7 +74,7 @@ impl TryFrom<String> for DocumentId {
}

/// (unencrypted) name of a document. Construct via `try_from(&str)`
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct DocumentName(pub(crate) String);
impl DocumentName {
pub fn name(&self) -> &String {
Expand All @@ -92,7 +92,7 @@ impl TryFrom<&str> for DocumentName {
struct DocHeaderPacked(Vec<u8>);

/// Represents a parsed document header which is decoded from JSON
#[derive(Debug, Serialize, Deserialize, PartialEq)]
#[derive(Debug, PartialEq, Serialize, Deserialize)]
struct DocumentHeader {
#[serde(rename = "_did_")]
document_id: DocumentId,
Expand Down Expand Up @@ -161,7 +161,7 @@ fn parse_document_parts(
}

/// Represents the reason a document can be viewed by the requesting user.
#[derive(Serialize, Deserialize, Debug, Clone, Hash, PartialEq, Eq)]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum AssociationType {
/// User created the document
Expand All @@ -173,7 +173,7 @@ pub enum AssociationType {
}

/// Represents a User struct which is returned from doc get to show the IDs of users the document is visible to
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct VisibleUser {
id: UserId,
}
Expand All @@ -184,7 +184,7 @@ impl VisibleUser {
}

/// Represents a Group struct which is returned from doc get to show the IDs and names of groups the document is visible to
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct VisibleGroup {
id: GroupId,
name: Option<GroupName>,
Expand All @@ -201,7 +201,7 @@ impl VisibleGroup {
/// Single document's (abbreviated) metadata. Returned as part of a `DocumentListResult`.
///
/// If you want full metadata for a document, see `DocumentMetadataResult`
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct DocumentListMeta(DocumentListApiResponseItem);
impl DocumentListMeta {
pub fn id(&self) -> &DocumentId {
Expand All @@ -222,7 +222,7 @@ impl DocumentListMeta {
}

/// Metadata for each of the documents that the current user has access to decrypt.
#[derive(Debug)]
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct DocumentListResult {
result: Vec<DocumentListMeta>,
}
Expand All @@ -233,7 +233,7 @@ impl DocumentListResult {
}

/// Full metadata for a document.
#[derive(Clone)]
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct DocumentMetadataResult(DocumentMetaApiResponse);
impl DocumentMetadataResult {
pub fn id(&self) -> &DocumentId {
Expand Down Expand Up @@ -273,7 +273,7 @@ impl DocumentMetadataResult {
/// - `encrypted_data` - Bytes of encrypted document content
/// - `encrypted_deks` - List of encrypted document encryption keys (EDEK) of users/groups that have been granted access to `encrypted_data`
/// - `access_errs` - Users and groups that could not be granted access
#[derive(Debug)]
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct DocumentEncryptUnmanagedResult {
id: DocumentId,
encrypted_data: Vec<u8>,
Expand Down Expand Up @@ -329,7 +329,7 @@ impl DocumentEncryptUnmanagedResult {
/// - `encrypted_data` - Bytes of encrypted document content
/// - `grants` - Users and groups that have access to decrypt the `encrypted_data`
/// - `access_errs` - Users and groups that could not be granted access
#[derive(Debug)]
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct DocumentEncryptResult {
id: DocumentId,
name: Option<DocumentName>,
Expand Down Expand Up @@ -363,7 +363,7 @@ impl DocumentEncryptResult {
}
}
/// Result of decrypting a document. Includes minimal metadata as well as the decrypted bytes.
#[derive(Debug, PartialEq, Clone)]
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct DocumentDecryptResult {
id: DocumentId,
name: Option<DocumentName>,
Expand All @@ -390,7 +390,7 @@ impl DocumentDecryptResult {
}

/// A failure to edit the access list of a document.
#[derive(Debug, Clone)]
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct DocAccessEditErr {
/// User or group whose access was to be granted/revoked
pub user_or_group: UserOrGroup,
Expand All @@ -409,7 +409,7 @@ impl DocAccessEditErr {

/// Result of granting or revoking access to a document. Both grant and revoke support partial
/// success.
#[derive(Debug)]
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct DocumentAccessResult {
succeeded: Vec<UserOrGroup>,
failed: Vec<DocAccessEditErr>,
Expand All @@ -433,11 +433,11 @@ impl DocumentAccessResult {
&self.failed
}
}
#[derive(Clone, PartialEq, Debug)]
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
struct DecryptedData(Vec<u8>);

/// Result of successful unmanaged decryption
#[derive(Clone, PartialEq, Debug)]
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct DocumentDecryptUnmanagedResult {
id: DocumentId,
access_via: UserOrGroup,
Expand All @@ -462,7 +462,7 @@ impl DocumentDecryptUnmanagedResult {
}

/// Either a user or a group. Allows for containing both.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", tag = "type")]
pub enum UserOrGroup {
User { id: UserId },
Expand Down Expand Up @@ -785,7 +785,7 @@ fn recrypt_document<CR: rand::CryptoRng + rand::RngCore>(
/// Once decrypted, the DEK serves as a symmetric encryption key.
///
/// It can also be useful to think of an EDEK as representing a "document access grant" to a user/group.
#[derive(Debug, Clone, PartialEq)]
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct EncryptedDek {
grant_to: WithKey<UserOrGroup>,
encrypted_dek_data: recrypt::api::EncryptedValue,
Expand Down Expand Up @@ -859,7 +859,7 @@ impl TryFrom<&EncryptedDek> for EncryptedDekP {
/// Result of recrypt encryption. Contains the encrypted DEKs and the encrypted (user) data.
/// `RecryptionResult` is an intermediate value as it cannot be serialized to bytes directly.
/// To serialize to bytes, first construct an `EncryptedDoc`
#[derive(Debug, Clone)]
#[derive(Clone, Debug)]
struct RecryptionResult {
edeks: Vec<EncryptedDek>,
encrypted_data: AesEncryptedValue,
Expand Down