Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 088bab4

Browse files
committed
Merge pull request #95 from AzureAD/dev
Dev
2 parents f7e9b88 + 24a1b5f commit 088bab4

36 files changed

Lines changed: 583 additions & 382 deletions

samples/rms_sample/mainwindow.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ MainWindow::MainWindow(QWidget *parent)
138138
: QMainWindow(parent)
139139
, ui(new Ui::MainWindow)
140140
, templatesUI(this)
141+
, cancelState(new std::atomic<bool>(false))
141142

142143
{
143144
ui->setupUi(this);
@@ -201,6 +202,10 @@ void MainWindow::addCertificates() {
201202

202203
void MainWindow::on_encryptPFILETemplatesButton_clicked()
203204
{
205+
if (ui->encryptPFILETemplatesButton->text() == "CANCEL") {
206+
cancelState->store(true);
207+
return;
208+
}
204209
string fileIn = SelectFile("Select file to encrypt");
205210

206211
if (!fileIn.empty()) {
@@ -277,6 +282,8 @@ void MainWindow::ConvertToPFILEUsingTemplates(const string& fileIn,
277282
fileExt = fileIn.substr(pos);
278283
}
279284

285+
ui->encryptPFILETemplatesButton->setText("CANCEL");
286+
280287
// create thread for conversion
281288
auto th = std::thread([inFile, outFile, self](
282289
const string _clientId,
@@ -288,10 +295,19 @@ void MainWindow::ConvertToPFILEUsingTemplates(const string& fileIn,
288295
// create UI authentication callback
289296
AuthCallbackUI authUI(self.get(), _clientId, _redirectUrl);
290297

298+
self->cancelState->store(false);
299+
291300
// process convertion
292301
PFileConverter::ConvertToPFileTemplatesAsync(
293-
_clientEmail, inFile, _fileExt, outFile, authUI,
294-
self->consent, self->templatesUI, std::launch::deferred).get();
302+
_clientEmail,
303+
inFile,
304+
_fileExt,
305+
outFile,
306+
authUI,
307+
self->consent,
308+
self->templatesUI,
309+
std::launch::deferred,
310+
self->cancelState).get();
295311

296312
postToMainThread([self, _fileOut]() {
297313
self->AddLog("Successfully converted to ", _fileOut.c_str());
@@ -313,6 +329,10 @@ void MainWindow::ConvertToPFILEUsingTemplates(const string& fileIn,
313329
}
314330
inFile->close();
315331
outFile->close();
332+
333+
postToMainThread([self]() {
334+
self->ui->encryptPFILETemplatesButton->setText("Encrypt Async (templates)");
335+
}, self.get());
316336
}, clientId, redirectUrl, clientEmail, fileExt, fileOut);
317337

318338
th.detach();
@@ -373,7 +393,8 @@ void MainWindow::ConvertToPFILEUsingRights(const string & fileIn,
373393
outFile,
374394
auth,
375395
this->consent,
376-
userRights);
396+
userRights,
397+
this->cancelState);
377398

378399
AddLog("Successfully converted to ", fileOut.c_str());
379400
}
@@ -438,7 +459,8 @@ void MainWindow::ConvertFromPFILE(const string& fileIn,
438459
inFile,
439460
outFile,
440461
auth,
441-
this->consent);
462+
this->consent,
463+
this->cancelState);
442464

443465
switch (pfs->m_status) {
444466
case Success:

samples/rms_sample/mainwindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ private slots:
103103
Ui::MainWindow *ui;
104104
ConsentCallback consent;
105105
TemplatesCallbackUI templatesUI;
106+
std::shared_ptr<std::atomic<bool> > cancelState;
106107

107108
void addCertificates();
108109
std::vector<UserRights>openRightsDlg();

samples/rms_sample/pfileconverter.cpp

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,14 @@ PFileConverter::~PFileConverter()
112112
{}
113113

114114
void PFileConverter::ConvertToPFilePredefinedRights(
115-
const string & userId,
116-
shared_ptr<istream> inStream,
117-
const string & fileExt,
118-
shared_ptr<iostream> outStream,
119-
IAuthenticationCallback & auth,
115+
const string & userId,
116+
shared_ptr<istream> inStream,
117+
const string & fileExt,
118+
shared_ptr<iostream> outStream,
119+
IAuthenticationCallback & auth,
120120
IConsentCallback& /*consent*/,
121-
const vector<UserRights>& userRights)
121+
const vector<UserRights> & userRights,
122+
std::shared_ptr<std::atomic<bool> >cancelState)
122123
{
123124
auto endValidation = chrono::system_clock::now() + chrono::hours(48);
124125

@@ -132,24 +133,25 @@ void PFileConverter::ConvertToPFilePredefinedRights(
132133
desc.Description("Test Description");
133134

134135
auto policy = UserPolicy::Create(desc, userId, auth,
135-
USER_AllowAuditedExtraction);
136+
USER_AllowAuditedExtraction, cancelState);
136137
ConvertToPFileUsingPolicy(policy, inStream, fileExt, outStream);
137138
}
138139

139140
future<bool>PFileConverter::ConvertToPFileTemplatesAsync(
140-
const string & userId,
141-
shared_ptr<istream> inStream,
142-
const string & fileExt,
143-
shared_ptr<iostream> outStream,
144-
IAuthenticationCallback& auth,
141+
const string & userId,
142+
shared_ptr<istream> inStream,
143+
const string & fileExt,
144+
shared_ptr<iostream> outStream,
145+
IAuthenticationCallback & auth,
145146
IConsentCallback& /*consent*/,
146-
ITemplatesCallback & templ,
147-
launch launchType)
147+
ITemplatesCallback & templ,
148+
launch launchType,
149+
std::shared_ptr<std::atomic<bool> >cancelState)
148150
{
149151
auto templatesFuture = TemplateDescriptor::GetTemplateListAsync(
150-
userId, auth, launch::deferred);
152+
userId, auth, launch::deferred, cancelState);
151153

152-
return async(launchType, [templatesFuture, &templ, &auth]
154+
return async(launchType, [templatesFuture, &templ, &auth, cancelState]
153155
(const string _userId,
154156
shared_ptr<istream>_inStream,
155157
const string _fileExt,
@@ -167,7 +169,8 @@ future<bool>PFileConverter::ConvertToPFileTemplatesAsync(
167169
_userId,
168170
auth,
169171
USER_AllowAuditedExtraction,
170-
signedData);
172+
signedData,
173+
cancelState);
171174

172175
ConvertToPFileUsingPolicy(policy, _inStream, _fileExt, _outStream);
173176
}
@@ -211,11 +214,12 @@ void PFileConverter::ConvertToPFileUsingPolicy(shared_ptr<UserPolicy>policy,
211214
}
212215

213216
shared_ptr<GetProtectedFileStreamResult>PFileConverter::ConvertFromPFile(
214-
const string & userId,
215-
shared_ptr<istream> inStream,
216-
shared_ptr<iostream> outStream,
217-
IAuthenticationCallback& auth,
218-
IConsentCallback & consent)
217+
const string & userId,
218+
shared_ptr<istream> inStream,
219+
shared_ptr<iostream> outStream,
220+
IAuthenticationCallback & auth,
221+
IConsentCallback & consent,
222+
std::shared_ptr<std::atomic<bool> >cancelState)
219223
{
220224
auto inIStream = rmscrypto::api::CreateStreamFromStdStream(inStream);
221225

@@ -226,7 +230,8 @@ shared_ptr<GetProtectedFileStreamResult>PFileConverter::ConvertFromPFile(
226230
&consent,
227231
POL_None,
228232
static_cast<ResponseCacheFlags>(RESPONSE_CACHE_INMEMORY
229-
| RESPONSE_CACHE_ONDISK));
233+
| RESPONSE_CACHE_ONDISK),
234+
cancelState);
230235

231236
if ((fsResult.get() != nullptr) && (fsResult->m_status == Success) &&
232237
(fsResult->m_stream != nullptr)) {

samples/rms_sample/pfileconverter.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ class PFileConverter {
3636
std::shared_ptr<std::iostream> outStream,
3737
rmscore::modernapi::IAuthenticationCallback & auth,
3838
rmscore::modernapi::IConsentCallback & consent,
39-
const std::vector<rmscore::modernapi::UserRights>& userRights);
39+
const std::vector<rmscore::modernapi::UserRights>& userRights,
40+
std::shared_ptr<std::atomic<bool> > cancelState);
4041
static std::future<bool>ConvertToPFileTemplatesAsync(
4142
const std::string & userId,
4243
std::shared_ptr<std::istream> inStream,
@@ -45,13 +46,15 @@ class PFileConverter {
4546
rmscore::modernapi::IAuthenticationCallback& auth,
4647
rmscore::modernapi::IConsentCallback & consent,
4748
ITemplatesCallback & templ,
48-
std::launch launchType);
49+
std::launch launchType,
50+
std::shared_ptr<std::atomic<bool> > cancelState);
4951
static std::shared_ptr<rmscore::modernapi::GetProtectedFileStreamResult>
5052
ConvertFromPFile(const std::string & userId,
5153
std::shared_ptr<std::istream> inStream,
5254
std::shared_ptr<std::iostream> outStream,
5355
rmscore::modernapi::IAuthenticationCallback& auth,
54-
rmscore::modernapi::IConsentCallback & consent);
56+
rmscore::modernapi::IConsentCallback & consent,
57+
std::shared_ptr<std::atomic<bool> > cancelState);
5558

5659
private:
5760

0 commit comments

Comments
 (0)