Merged in undo functionality from ENGINE-254
authorKrista Bennett <krista@pep-project.org>
Tue, 03 Oct 2017 16:23:57 +0200
changeset 21309943fcb0d532
parent 2127 da73aa9f2a94
parent 2129 fd3108a623c5
child 2131 334139882a97
child 2132 70105db2d539
Merged in undo functionality from ENGINE-254
     1.1 --- a/src/keymanagement.c	Mon Oct 02 13:02:41 2017 +0200
     1.2 +++ b/src/keymanagement.c	Tue Oct 03 16:23:57 2017 +0200
     1.3 @@ -723,12 +723,38 @@
     1.4      }
     1.5      else
     1.6      {
     1.7 +        // for undo
     1.8 +        if (session->cached_mistrusted)
     1.9 +            free(session->cached_mistrusted);
    1.10 +        session->cached_mistrusted = identity_dup(ident);
    1.11          status = mark_as_compromized(session, ident->fpr);
    1.12      }
    1.13  
    1.14      return status;
    1.15  }
    1.16  
    1.17 +DYNAMIC_API PEP_STATUS undo_last_mistrust(PEP_SESSION session) {
    1.18 +    assert(session);
    1.19 +    
    1.20 +    if (!session)
    1.21 +        return PEP_ILLEGAL_VALUE;
    1.22 +    
    1.23 +    PEP_STATUS status = PEP_STATUS_OK;
    1.24 +        
    1.25 +    pEp_identity* cached_ident = session->cached_mistrusted;
    1.26 +    
    1.27 +    if (!cached_ident)
    1.28 +        status = PEP_CANNOT_FIND_IDENTITY;
    1.29 +    else {
    1.30 +        status = set_identity(session, cached_ident);            
    1.31 +        free_identity(session->cached_mistrusted);
    1.32 +    }
    1.33 +    
    1.34 +    session->cached_mistrusted = NULL;
    1.35 +
    1.36 +    return status;
    1.37 +}
    1.38 +
    1.39  DYNAMIC_API PEP_STATUS key_reset_trust(
    1.40          PEP_SESSION session,
    1.41          pEp_identity *ident
     2.1 --- a/src/keymanagement.h	Mon Oct 02 13:02:41 2017 +0200
     2.2 +++ b/src/keymanagement.h	Tue Oct 03 16:23:57 2017 +0200
     2.3 @@ -125,17 +125,35 @@
     2.4      );
     2.5  
     2.6  
     2.7 -// key_mistrusted() - mark key as being compromized
     2.8 +// key_mistrusted() - mark key as being compromised
     2.9  //
    2.10  //  parameters:
    2.11  //      session (in)        session to use
    2.12 -//      ident (in)          person and key which was compromized
    2.13 +//      ident (in)          person and key which was compromised
    2.14  
    2.15  DYNAMIC_API PEP_STATUS key_mistrusted(
    2.16          PEP_SESSION session,
    2.17          pEp_identity *ident
    2.18      );
    2.19  
    2.20 +// undo_last_mistrust() - reset identity and trust status for the last
    2.21 +//                        identity in this session marked as mistrusted
    2.22 +//                        to their cached values from the time of mistrust
    2.23 +//  parameters:
    2.24 +//      session (in)        session to use
    2.25 +//
    2.26 +//  return value:
    2.27 +//      PEP_STATUS_OK if identity and trust were successfully restored.
    2.28 +//      Otherwise, error status from attempts to set.
    2.29 +//
    2.30 +//  caveat:
    2.31 +//      only works for this session, and only once. cache is invalidated
    2.32 +//      upon use.
    2.33 +//
    2.34 +//      WILL NOT WORK ON MISTRUSTED OWN KEY
    2.35 +
    2.36 +DYNAMIC_API PEP_STATUS undo_last_mistrust(PEP_SESSION session);
    2.37 +
    2.38  
    2.39  // trust_personal_key() - mark a key as trusted with a person
    2.40  //
     3.1 --- a/src/pEpEngine.h	Mon Oct 02 13:02:41 2017 +0200
     3.2 +++ b/src/pEpEngine.h	Tue Oct 03 16:23:57 2017 +0200
     3.3 @@ -862,6 +862,7 @@
     3.4  
     3.5  DYNAMIC_API PEP_STATUS get_trust(PEP_SESSION session, pEp_identity *identity);
     3.6  
     3.7 +
     3.8  PEP_STATUS set_trust(PEP_SESSION session, 
     3.9                              const char* user_id,
    3.10                              const char* fpr, 
     4.1 --- a/src/pEp_internal.h	Mon Oct 02 13:02:41 2017 +0200
     4.2 +++ b/src/pEp_internal.h	Tue Oct 03 16:23:57 2017 +0200
     4.3 @@ -173,6 +173,9 @@
     4.4      bool unencrypted_subject;
     4.5      bool keep_sync_msg;
     4.6      bool service_log;
     4.7 +
     4.8 +    // mistrust undo cache
     4.9 +    pEp_identity* cached_mistrusted;
    4.10      
    4.11  #ifdef DEBUG_ERRORSTACK
    4.12      stringlist_t* errorstack;