NCEntoToEndInterface.swift 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // NCEntoToEndInterface.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 03/04/17.
  6. // Copyright © 2017 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import Foundation
  24. class NCEntoToEndInterface : NSObject {
  25. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  26. override init() {
  27. }
  28. // --------------------------------------------------------------------------------------------
  29. // MARK: End To End Encryption
  30. // --------------------------------------------------------------------------------------------
  31. @objc func initEndToEndEncryption() {
  32. let metadataNet: CCMetadataNet = CCMetadataNet.init(account: appDelegate.activeAccount)
  33. metadataNet.action = actionGetEndToEndPublicKeys;
  34. appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  35. metadataNet.action = actionGetEndToEndPrivateKeyCipher;
  36. appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  37. metadataNet.action = actionGetEndToEndServerPublicKey;
  38. appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  39. }
  40. // --------------------------------------------------------------------------------------------
  41. // MARK: Mark/Delete Encrypted Folder
  42. // --------------------------------------------------------------------------------------------
  43. @objc func markEndToEndFolderEncryptedSuccess(_ metadataNet: CCMetadataNet) {
  44. print("E2E mark folder success")
  45. }
  46. @objc func markEndToEndFolderEncryptedFailure(_ metadataNet: CCMetadataNet, message: NSString, errorCode: NSInteger)
  47. {
  48. // Unauthorized
  49. if (errorCode == kOCErrorServerUnauthorized) {
  50. appDelegate.openLoginView(appDelegate.activeMain, loginType: loginModifyPasswordUser)
  51. }
  52. if (errorCode != kOCErrorServerUnauthorized) {
  53. appDelegate.messageNotification("_error_", description: message as String!, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  54. }
  55. }
  56. @objc func markEndToEndFolderEncrypted(_ metadata: tableMetadata) {
  57. let metadataNet: CCMetadataNet = CCMetadataNet.init(account: appDelegate.activeAccount)
  58. metadataNet.action = actionMarkEndToEndFolderEncrypted;
  59. metadataNet.fileID = metadata.fileID;
  60. appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  61. }
  62. @objc func deleteEndToEndFolderEncryptedSuccess(_ metadataNet: CCMetadataNet) {
  63. print("E2E delete folder success")
  64. }
  65. @objc func deleteEndToEndFolderEncryptedFailure(_ metadataNet: CCMetadataNet, message: NSString, errorCode: NSInteger)
  66. {
  67. // Unauthorized
  68. if (errorCode == kOCErrorServerUnauthorized) {
  69. appDelegate.openLoginView(appDelegate.activeMain, loginType: loginModifyPasswordUser)
  70. }
  71. if (errorCode != kOCErrorServerUnauthorized) {
  72. appDelegate.messageNotification("_error_", description: message as String!, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  73. }
  74. }
  75. @objc func deleteEndToEndFolderEncrypted(_ metadata: tableMetadata) {
  76. let metadataNet: CCMetadataNet = CCMetadataNet.init(account: appDelegate.activeAccount)
  77. metadataNet.action = actionDeleteEndToEndFolderEncrypted;
  78. metadataNet.fileID = metadata.fileID;
  79. appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  80. }
  81. }