Method and related device for canceling encryption and decryption tasks under iOS platform
By creating encapsulation and wrapper classes on the iOS platform, task cancellation across different languages is achieved. Status codes and weak references are used to manage object lifecycles, solving the problem of inaccurate encryption and decryption task cancellation on the iOS platform and improving the reliability and efficiency of task cancellation.
Patent Information
- Application Number
- CN202011185235.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-29
- Publication Date
- 2026-05-29
- Estimated Expiration
- 2040-10-29
AI Technical Summary
On the iOS platform, existing technologies cannot accurately cancel encryption/decryption tasks and cannot provide event receipts indicating whether task cancellation was successful, leading to application-level errors and incurring the overhead of traversing the task queue.
By creating encapsulation and wrapper classes, mutual calls between different programming languages are achieved. The encapsulation class contains the object to be passed and provides task cancellation command interface and data interface. Status codes are used to refine the task status, and weak reference smart pointers are used to manage the object lifecycle to avoid memory leaks and program crashes.
It enables precise cancellation of each stage of encryption/decryption tasks, reduces computational overhead, avoids application-layer errors, and improves the reliability and efficiency of task cancellation.
Smart Images

Figure CN114428687B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of software operating system control technology, and in particular to a method and related equipment for canceling encryption and decryption tasks on the iOS platform. Background Technology
[0002] In existing operating systems, task cancellation can be achieved directly by calling the task cancellation function through the encryption / decryption task interface. However, on the iOS platform, network libraries are primarily developed based on the system network library, which is written in Objective-C. The task request and cancellation initiator is called by the application-layer function in Objective-C, while the underlying encryption / decryption request is written in C++. A task cancellation function needs to be designed to bridge the gap between these two languages. Since the two languages differ, the lifecycle of each object also differs. The design must consider the lifecycle of both languages and object management to avoid leaks during internal testing.
[0003] Existing or traditional solutions typically use encrypting / decrypting task IDs to cancel task requests, or mark a task as canceled after it's completed. This approach only allows for coarse-grained cancellation, lacking precision down to individual task stages. Furthermore, there's no event feedback indicating successful cancellation, leaving the caller unaware of the status. The cancellation function requires traversing the task queue, incurring overhead. Extreme cases can lead to application-layer errors. Therefore, a secure, reliable, and stable solution is needed to enable mutual calls between the two calling objects. Summary of the Invention
[0004] This invention provides a method for canceling encryption / decryption tasks on the iOS platform. It encapsulates the command interface call as a pass object and packages the pass object so that calling functions under different programming language architectures hold the same encapsulated pass object, enabling mutual calling of the encapsulated pass object between different programming languages and avoiding application layer errors.
[0005] Another objective of this invention is to create parameters and status codes within the callback interface to represent the execution result and status of the encryption / decryption task, thereby refining the details of each stage of the encryption task cancellation function and enabling the caller to accurately perceive the execution status of the encryption task cancellation function.
[0006] The technical solution provided by this invention is as follows:
[0007] A method for canceling encryption / decryption tasks on the iOS platform includes:
[0008] Create a task class that includes an encryption / decryption task request callback interface to enable the cancellation of encryption / decryption tasks;
[0009] Create a wrapper class with state variables, which contains a pass object to provide the caller with a task cancellation command interface and / or a data interface;
[0010] Create a wrapper class and wrap the wrapper class so that calling functions under different programming language architectures hold the same wrapper class object, enabling mutual calling of objects between different programming languages.
[0011] Preferably, the process of creating the task class includes:
[0012] Within the callback interface, parameters representing the execution result and task status of the encryption / decryption task are created to implement the functionality of each callback interface;
[0013] The callback interfaces include callback interfaces for successful encryption / decryption, callback interfaces for encryption / decryption errors, and callback interfaces for actual task cancellation; and
[0014] Create a state set for the task state parameters, the state set containing a state code that marks the task state;
[0015] The status code indicates the execution result and status of the encryption / decryption task, and includes one or more of the following: encryption / decryption task in progress, generating encryption / decryption key, preparing encryption / decryption data, encrypting data, decrypting data, task cancelled, task successful, and task cancelled.
[0016] Preferably, the creation process of the encapsulated class includes:
[0017] Construct a wrapper function;
[0018] A cancellation command interface is set within the encapsulated class, allowing the caller to cancel the encryption / decryption task through this interface.
[0019] A cancellation command query interface is set within the encapsulation class, allowing the caller to query the cancellation command for the encryption / decryption task.
[0020] The cancellation command interface includes status variables, which are Boolean atomic variables and include cancellation status variables and non-cancellation status variables.
[0021] Preferably, the creation process of the wrapper class includes:
[0022] Define member variables and establish weak reference smart pointers that do not control the lifecycle of objects. The weak reference smart pointers hold the wrapper class and use the passed objects in the wrapper class as managed objects.
[0023] Construct an assignment function to assign a value to the object passed to the encryption / decryption / cancellation task within the encapsulated class, and establish parameters to pass the assigned object to a weak reference smart pointer.
[0024] Establish a cancellation interface and use the weak reference smart pointer to detect whether the passed object has been released by the C++ layer. If it has not been released, execute the cancellation task.
[0025] Establish a query cancellation interface and use the weak reference smart pointer to detect whether the passed object has been released by the C++ layer. If it has not been released, execute the query cancellation task.
[0026] Preferably, it also includes:
[0027] When a caller submits a request to cancel an encryption / decryption task through the cancellation command interface and / or query the cancellation command interface, the C++ layer returns a handle to a cancellation task object, which then calls the corresponding task callback interface to execute the cancellation function.
[0028] Preferably, the interface construction process for canceling the task object handle in the C++ layer includes:
[0029] Establish a reference-counting smart pointer, which holds the passed object within the encapsulation class and is capable of creating and destroying the passed object;
[0030] Establish a shared pointer to the encapsulated class and return a corresponding weak reference smart pointer management object to the caller;
[0031] When the weak reference smart pointer is returned to the caller, a copy operation is used to return it, so that the C++ layer and the caller use the same passed object.
[0032] Preferably, it also includes checking and verifying the encryption / decryption task cancellation status parameters, which is achieved through the following steps:
[0033] Create a review class and use the object to be passed when the decryption task is canceled, the status corresponding to the cancellation of the decryption task, and the task callback object as member variables;
[0034] Establish an object constructor and check whether the object to which the decryption task was cancelled was internally cancelled.
[0035] If cancelled, the callback task is cancelled, the corresponding status parameter is passed in, and the caller is notified.
[0036] A device with encryption / decryption task cancellation functionality on the iOS platform includes:
[0037] The functional module is used to create task classes that include an encryption / decryption task request callback interface to enable the cancellation of encryption / decryption tasks;
[0038] An encapsulation module is used to create encapsulation classes with state variables, which contain a pass object to provide the caller with a task cancellation interface and / or a data interface.
[0039] The module wraps the encapsulated class, enabling calling functions under different programming language architectures to hold the same encapsulated class object, thus achieving mutual calling of encapsulated class objects between different programming languages.
[0040] An electronic device includes an application processor and a memory, the processor being configured to implement the steps of the encryption / decryption task cancellation method under the iOS platform via a computer management program in the memory.
[0041] A computer-readable storage medium storing a computer management program thereon, wherein the computer management program, when executed by a processor, implements the steps of a method for canceling encryption / decryption tasks on the iOS platform.
[0042] Beneficial effects
[0043] This invention provides a method for canceling encryption / decryption tasks on the iOS platform. It encapsulates the command interface call as a pass object and packages the pass object so that calling functions under different programming language architectures hold the same encapsulated pass object, enabling mutual calling of the encapsulated pass object between different programming languages and avoiding application layer errors.
[0044] The task status parameters provided by this invention include status codes that mark the task status, thereby refining the encryption and decryption task stages. This allows for more precise control over each stage of the encryption and decryption task. The status codes enable the cancellation of each level of the encryption and decryption task, resulting in finer granularity, better performance, and reduced unnecessary computation.
[0045] This invention is designed to pass an interface object instead of returning the entire encryption task to the caller. The purpose is to reduce the caller's awareness of the details of the encryption task, thereby reducing their control over the encryption task. It provides the caller with the smallest granular data they need, without exposing the data of each stage of encryption, avoiding access by the caller, and reducing the possibility of errors. Attached Figure Description
[0046] Figure 1 This is a flowchart illustrating the method for canceling encryption / decryption tasks on the iOS platform as described in this invention.
[0047] Figure 2 This is a flowchart illustrating the creation process of the packaging class described in this invention.
[0048] Figure 3 This is a schematic diagram of the device with encryption / decryption task cancellation function under the iOS platform according to the present invention.
[0049] Figure 4 A schematic diagram of the hardware structure of a device with encryption / decryption task cancellation function on the iOS platform provided in this application embodiment;
[0050] Figure 5 This is a schematic diagram illustrating a possible embodiment of an electronic device provided in this application.
[0051] Figure 6 This is a schematic diagram illustrating one possible embodiment of a computer-readable storage medium provided in this application. Detailed Implementation
[0052] The following specific embodiments illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0053] It should be noted that in the description of this invention, terms such as "center," "upper," "lower," "horizontal," and "inner," indicating directional or positional relationships, are based on the directional or positional relationships shown in the accompanying drawings. These are merely for ease of description and do not indicate or imply that the device or element must have a specific orientation, or be constructed and operated in a specific orientation; therefore, they should not be construed as limitations on this invention. Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0054] Furthermore, it should be noted that, in the description of this invention, unless otherwise explicitly specified and limited, the terms "set," "install," "connect," and "link" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal communication between two components. Those skilled in the art can understand the specific meaning of the above terms in this invention according to the specific circumstances.
[0055] like Figure 1 As shown, based on the technical problems raised in the background section, this invention provides a method for canceling encryption / decryption tasks on the iOS platform, comprising the following steps:
[0056] Step S110: Create a task class that includes an encryption / decryption task request callback interface to implement the cancellation of encryption / decryption tasks. Specifically, design a callback interface for encryption task requests, which includes each stage of the encryption task process, as well as a successful cancellation callback for the task cancellation function. Using task callbacks makes it easier to implement the cancellation function and easily solves the problem of extreme asynchronous thread call timings causing task cancellation to be triggered only after task execution is complete. The specific programming language is as follows:
[0057] Class Callback{
[0058] virtual ~Callback() = default;
[0059] virtual void OnSucceeded(Ressult* result, Status s)=0;
[0060] virtual void OnError(exception* ex, Status s)=0;
[0061] Virtual void OnCancel(Status s);=0;}
[0062] The `Class Callback{` class represents a task callback interface; `virtual ~Callback() = default}` is a virtual destructor to prevent memory leaks. `virtual void OnSucceeded(Ressult*result, Status s)=0` is the callback function for successful encryption / decryption, where `result` represents the execution result and `status` represents the task's status. `virtual void OnError(exception* ex, Status s)=0` is the callback function for encryption / decryption errors. `virtual void OnCancel(Status s)=0` is the callback function for actual task cancellation. This interface can notify the application layer of task cancellation when the task is actually cancelled.
[0063] The task status parameters include status codes that indicate the task status, thus refining the encryption and decryption task stages. Specifically, a status code is designed to mark the current state of the encryption task, allowing the business layer Objective-C to know the task status whether it is canceled or not. In this embodiment, a specific programming language example is given, as follows:
[0064] Enmu Status{
[0065] Prepare = 0,
[0066] key,
[0067] data,
[0068] Encrypt,
[0069] Decrypt,
[0070] Cancel
[0071] Suces,
[0072] Error}
[0073] The status codes correspond to the task status: Prepare = 0, indicating that the encryption / decryption task is being prepared; key, indicating that the encryption / decryption key is being generated; data, indicating that the encryption / decryption data is being prepared; Encrypt, indicating that the data is being encrypted; Decrypt, indicating that the data is being decrypted; Cancel, indicating that the task has been canceled; Success, indicating that the task was successful; and Error, indicating that the task was canceled.
[0074] In this embodiment, these states are defined in a finer detail, down to each stage of the encryption / decryption task. This allows each stage of the encryption / decryption task to be canceled, resulting in finer granularity, better performance, and avoiding unnecessary computations due to task cancellation.
[0075] Step S120: Create a wrapper class with state variables. The wrapper class contains a passable object to provide the caller with a task cancellation command interface and / or data interface.
[0076] Specifically, when designing a request for an encryption task, a handler object is returned to the caller. This handler object provides the functionality to cancel the task. In this embodiment, instead of returning the entire encryption task to the caller, a handler is designed. The aim is to reduce the caller's awareness of the details of the encryption task, thereby reducing their control over it. Only the smallest granularity of data needed is provided to the caller. Therefore, this invention designs a scheme for canceling the task with the smallest granularity of data, while not exposing data such as data from various stages of encryption, thus preventing the caller from accessing it and reducing the possibility of errors. The handler is the object that transmits the task cancellation command interface and / or data interface to the caller. The caller can use the interface to cancel the encryption / decryption task.
[0077] The design of a programming language for creating encapsulated classes is as follows:
[0078] Class THandle {
[0079] atomic <bool>flag_{false};
[0080] THandle() {} is the constructor function.
[0081] void cancel() {flag_ = true;}
[0082] bool isCancel() const {return flag_;}
[0083] The `Class THandle {` class creates a `THandle` instance to encapsulate the cancellation functionality and data. (atomic) <bool>`flag_{false};` This function has only one member variable, `flag_`, which is an atomic variable of type `bool` in this embodiment. It can express both canceled and non-cancelled states. Since the `flag_` variable is accessed by the underlying encryption algorithm, which involves multi-threaded access, and the caller (Objective-C) might use an asynchronous thread to cancel, traditional solutions might use locking mechanisms. Using an atomic variable avoids multi-threaded locking, improving performance. `THandle() {}` is the constructor. `void cancel() {flag_ = true;}` provides an interface to set the cancellation function; calling `cancel` sets `flag_` to `true` to indicate that the task is canceled. `bool isCancel() const {returnflag_;}` constructs a query statement, allowing the caller to check whether the task has been canceled.
[0084] In this embodiment, the caller can issue a command to cancel the encryption / decryption task through the encapsulated interface, and can obtain an event receipt indicating whether the cancellation was successful by querying the interface, thereby gaining awareness of the task's execution status. Furthermore, instead of returning the entire encryption task to the caller, the interface object is passed, aiming to reduce the caller's awareness of the details of the encryption task, thus reducing their control over it. The caller is given only the minimum granular data they need, minimizing the possibility of errors.
[0085] Step S130: Create a wrapper class and wrap the wrapper class so that calling functions under different programming language architectures hold the same wrapper class object, thereby realizing mutual calling of objects between different programming languages.
[0086] This embodiment is designed based on mutual calls between OJBect-C and C++. The lifecycles of the OJBect-C caller and the C++ internal encryption / decryption executor are different, and their object management also differs. Therefore, we do not want to expose too many cancellation implementation details to the caller. If the `THandle` is directly returned to the caller, the `handle` object would be held by both the caller and the underlying C++ implementation, which would cause problems. Therefore, this embodiment uses weak references, which are typically used to resolve circular dependencies.
[0087] like Figure 2 As shown, the specific solution is as follows:
[0088] Step S131: Define member variables and establish a weak reference smart pointer that does not control the lifecycle of the object. The weak reference smart pointer holds the encapsulation class and uses the passed object in the encapsulation class as the managed object.
[0089] Step S132: Construct an assignment function to assign a value to the passed object in the encapsulated class, and establish parameters to pass the assigned object to the weak reference smart pointer.
[0090] Specifically, the design of the programming language for creating wrapper classes is as follows:
[0091] class TWrapHandle
[0092] weak_ptr <thandle>handler_;
[0093] TWrapHandle(weak_ptr <thandle>handler) :
[0094] handler_(handler){}
[0095] bool cancel(){if (auto ptr = handler_.lock())
[0096] ptr->cancel(); returns true;
[0097] else { return false;}
[0098] bool isCancel() const {
[0099] ,if (auto ptr = handler_.lock())
[0100] {return ptr->isCancel();
[0101] Else {return false;}
[0102] Specifically, the class `TWrapHandle {` is created as a wrapper class to wrap `THandle`, using a weak reference. Member variable: `weak_ptr` <thandle>The `handler_` member variable uses a `weak_ptr` (smart pointer) to hold a `THandle`. Constructor: `TWrapHandle(weak_ptr)` <thandle>The constructor `handler_` assigns a value to `handler_` and requires a `weak_ptr` parameter. <thandle>An object of (smart pointer).
[0103] This embodiment uses weak references to address the situation where OJBect-C and C++ mutually hold the same object. This ensures that even if C++ releases the object THandle, OJBect-C's continued access to THandle will not cause a program crash due to THandle's release, as THandle release and cancellation are unsuccessful. Furthermore, since the caller holds a weak reference, if the underlying C++ library releases the object during encryption / decryption tasks, and the caller holds a weak reference, program crashes can be avoided.
[0104] In another embodiment, the copy constructor and assignment constructor cannot be defined as private; they must use the system default public ones. That is, the three functions TWrapHandle(const TWrapHandle&handle) and TWrapHandle(TWrapHandle&handle) and the assignment constructor TWrapHandle&operator=(const TWrapHandle&a) are automatically generated by the system so that different calling objects can obtain the copy constructor and assignment constructor.
[0105] In another embodiment, a pass object query function is also included to query whether the cancellation task was executed or completed by another object.
[0106] Step S133: Establish a cancellation interface and use the weak reference smart pointer to detect whether the passed object has been released by the C++ layer. If it has not been released, execute the cancellation task.
[0107] A query cancellation interface is established. The weak reference smart pointer is used to detect whether the passed object has been released by the C++ layer. If it has not been released, the query cancellation task is executed.
[0108] Specifically, the programming language for implementing the function to cancel the API query is as follows:
[0109] bool cancel(){if (auto ptr = handler_.lock());
[0110] ptr->cancel();
[0111] return true;
[0112] else { return false;}
[0113] The `bool cancel()` method uses the `handler_.lock()` interface. It first checks if the `handler_` object is still valid and has been released by C++. If not, it cancels the operation; otherwise, it doesn't. `ptr->cancel()` calls the `THandle`'s `cancel` interface and returns `true`. Otherwise, it returns `false`. If the object has been released, it doesn't cancel and returns `false`, indicating that the encryption / decryption task has been completed or destroyed, and cancellation is unnecessary.
[0114] The programming language used to implement the query cancellation function is as follows:
[0115] bool isCancel() const {
[0116] if (auto ptr = handler_.lock())
[0117] {return ptr->isCancel();
[0118] Else {return false;}
[0119] Here, `bool isCancel() const` queries the cancellation interface; it's only a query here, hence the `const` modifier. Similarly, it needs to check if the `handler_` object is still valid: `if (auto ptr = handler_.lock()){return ptr->isCancel();` calls the `THandle`'s `isCancel` interface to determine if cancellation has occurred. `Else{return false;}` If the object hasn't been released, cancellation is performed; otherwise, it's not. If the object has been released, cancellation is not performed, and `false` is returned. This indicates that the encryption / decryption task has been completed or destroyed, and cancellation is unnecessary.
[0120] In this embodiment, an encapsulation layer is used to encapsulate the transmitted object. This can prevent program crashes. Alternatively, the encapsulation layer can be omitted. The implementation process is as follows:
[0121] ojbect-c requires you to hold your own weak_ptr. <thandle>The handler object, and when calling cancellation and checking whether cancellation has been performed, requires deliberately calling if (auto ptr = handler_.lock()) to check whether the handler has been destroyed. The determination and maintenance of this is left to the users of ojbect-c, who are not C++ layer developers. It is easy to overlook or forget to make the judgment, which may lead to program crash.
[0122] Therefore, this embodiment designs a wrapper (TWrapHandle) layer to encapsulate the specific details into the C++ layer, which is transparent to users of Objective-C. The caller does not need to care about and cannot ignore the judgment of handler_, which would cause the program to crash.
[0123] In another embodiment, when the caller submits an encryption / decryption task cancellation request through the cancellation command interface and / or query command interface, the C++ layer returns a task cancellation object handle, which then calls the corresponding task callback interface to execute the cancellation function.
[0124] Specifically, the design of the C++ layer to return the object handle for task cancellation is as follows:
[0125] After ojbect-c invokes an encryption / decryption task, the C++ layer can return an object handle for canceling the task, allowing it to cancel the task. At the lower level of the C++ layer, data encryption and decryption functionality is provided. This is encapsulated in the `encryptCore` class, whose core data and interface design are as follows:
[0126] Class encryptCore{
[0127] shared_ptr <thandle>handler_;
[0128] TWrapHandle encrypt(void* data);
[0129] handler_ = make_shared <thandle>();
[0130] Retun TWrapHandle(handler_);}
[0131] Among them, Class encryptCore{ is the core data interface, shared_ptr <thandle>handler_ is a member variable that needs to be held by shared_ptr. This means that encryptCore is responsible for the creation and destruction of the THandle object and maintains its lifecycle.
[0132] The `TWrapHandle encrypt(void* data)` method is an encryption / decryption interface. The core of this interface is creating a `THandle` and then a `TWrapHandle`, returning a `TWrapHandle` object to Objective-C. The first step is object creation: `handler_ = make_shared`. <thandle>() creates a shared pointer to a TWrapHandle; ReturnTWrapHandle(handler_);} and returns a TWrapHandle object.
[0133] As a preferred embodiment, this requires returning a copy operation of the object used, and cannot return a pointer to TWrapHandle. Therefore, the caller, objectc, will copy the TWrapHandle object. Since the TWrapHandle object it holds is not a pointer, it will automatically be released after its lifetime expires. This allows objectc to freely copy the TWrapHandle object without worrying about its lifetime. The lifetime of the TWrapHandle object for task cancellation is handled using weak_ptr. <thandle>To hold a reference to an object. And C++ and Ojbect-C must use the same THandle object. Ojbect-C holds a weak_ptr. <thandle>This will not cause C++ to fail to release shared_ptr. <thandle>In the case of objects, the two sides do not depend on each other. As a preferred option, when executing or querying a cancellation task, encryption and decryption tasks need to be set up in the C++ layer. The specific process is as follows:
[0134] Since each event point is a function, it's necessary to check if it has been cancelled before executing the specific function. This would prevent the function from being executed again. Furthermore, since cancellation cannot be forcibly performed during function execution, a second check can be performed after execution to ensure it wasn't cancelled. This also avoids the situation where the task completion event is called back before the task completion event is completed. The specific code is as follows:
[0135] Class AutoCheck{
[0136] TWrapHandle handle_;
[0137] status status_;
[0138] Callback callback_;
[0139] AutoCheck(TWrapHandle thandle, status status, Callback callback):handle_(handle), status_(status), callback_(callback){ If (handler_->isCancel()) callback_->OnCancel(status_);}
[0140] Where ~AutoCheck(){ defines the check class, If (handler_->isCancel()) callback_->OnCancel(status_);} indicates whether the task has been cancelled, Class AutoCheck{
[0141] `TWrapHandle handle_;` defines the passed object within the wrapper class as a member variable of the check class; `status status_;` is a member variable recording the current status; `allback callback_;` is the callback object. `AutoCheck(TWrapHandle handle_, status status, Callback callback)`: `handle_(handle), status_(status), callback_(callback){ If (handler_->isCancel()) callback_->OnCancel(status_);}` The check's member variables include the wrapper class, wrapper class, status code, and callback object. The conditional statement `~AutoCheck(){ If (handler_->isCancel()) callback_->OnCancel(status_);}` checks if the passed object task has been canceled; if so, it returns the corresponding stage status.
[0142] The review class ensures that each function checks for cancellation at the beginning and end. Cancellation events must be executed after the task has finished, and checks must be performed at the beginning and end of each function. Designing an object constructor to check and a destructor to check again prevents developers from forgetting to check or only checking at the beginning of a function while ignoring it at the end.
[0143] The programming language used for designing the core data and interfaces is:
[0144] Class encryptCore{ .
[0145] status status_;
[0146] Void Prepare(){
[0147] status_ = Prepare;
[0148] AutoCheck auto(handler_, status_, callback_);
[0149] If (handler_->isCancel())
[0150] callback_->OnCancel(status_);
[0151] Else
[0152] Void key(){
[0153] status_ = key;
[0154] AutoCheck auto(handler_, status_, callback_);
[0155] If (handler_->isCancel()) {callback_->OnCancel(status_);}
[0156] Else {Continue to prepare key data}
[0157] Void Sucess(){
[0158] If (handler_->isCancel()) {callback_->OnCancel(Cancel);}
[0159] status_ = Sucess;
[0160] callback_->OnSucess(status_);
[0161] Or callback_->OnError(status_);
[0162] }
[0163] The `encryptCore` class holds a `callback` object and performs data encryption / decryption based on the various `status` values mentioned above. It also checks if the current task has been cancelled. Member variables: `Callback callback_` holds an Objective-C implementation of a `Callback` subclass. Objective-C needs to implement the callback functionality for encryption / decryption tasks based on the defined interfaces. Specifically, it implements the functionality of each interface. Member variables: `status_`; the current encryption / decryption status. Member functions: `Void Prepare(){status_ = Prepare; to assign a value to the status variable. AutoCheck auto(handler_, status_, callback_);` internally checks for task cancellation. `If (handler_->isCancel())` first checks if the encryption / decryption task has been cancelled. If cancelled, it directly calls back the task cancellation function. `callback_->OnCancel(status_);` passing the status `status_` at the time of cancellation, so the caller Objective-C knows the status at which the task was cancelled. `Else {` continues to complete the data preparation function.}` Member functions:
[0164] `void key(){status_ = key;}` This first assigns a value to the status variable. `AutoCheck auto(handler_,status_, callback_)` internally checks if the task is canceled. If `handler_->isCancel()`, then `callback_->OnCancel(status_);`. Otherwise, it prepares the data for `key`. Similarly, the checks for other statuses are the same as above, but separate modifications are needed for `Suces` and `Erro`.
[0165] The implementation of the member function `Void Success()` is the same as that of `Error`. Before completing the callback, the task's cancellation function must be checked. If cancellation is required, the status cannot be set to `Success` but must be set to `Cancel`, otherwise it will cause task misalignment. `If (handler_->isCancel()) {callback_->OnCancel(Cancel);}` Only when the current task is not cancelled can the success or failure of the callback task be determined. `status_ =Success; callback_->OnSuccess(status_);` or `callback_->OnError(status_);` When the encryption / decryption task has been completed, a cancellation function is sent to the Objective-C task. This embodiment's design prevents Objective-C from causing task misalignment by changing the task status to cancelled and cancelling the task completion callback.
[0166] In another embodiment, to enable code to be called in both languages, the present invention also designs the logic of the iOS Object-C layer.
[0167] In the Ojbect-C layer, the TWrapHandle object returned by the encrypt interface of encryptCore needs to be stored. In its implementation code, the file needs to be set to .mm format, indicating that it will use mixed calls between Objective-C and C++. The header file is still .h, but the TWrapHandle member is not stored in the .h file; instead, it is stored in the .mm file. The existence of TWrapHandle is not exposed externally; only a cancellation interface is exposed in the .h file. Therefore, other Ojbect-C code does not need to know about the existence of the TWrapHandle member when using the cancellation function, allowing other Ojbect-C code to be written in .m format. If TWrapHandle were stored in the .h file, all Ojbect-C code would have to use the .mm format, thus breaking Ojbect-C.
[0168] In this embodiment, the logic of the iOS OJBect-C layer is designed to ensure that the code can be called in both languages, thus avoiding errors at the application layer.
[0169] The method for canceling encryption / decryption tasks on the iOS platform in the embodiments of this application has been described above. The apparatus with the function of canceling encryption / decryption tasks on the iOS platform in the embodiments of this application is described below.
[0170] like Figure 3 As shown, this embodiment of the invention also provides an embodiment of a device with encryption / decryption task cancellation function under the iOS platform. The device includes: a functional module 210, an encapsulation module 220, and a packaging module 230.
[0171] Functional module 210 is used to create a task class that includes an encryption / decryption task request callback interface, and to create parameters representing the execution result and task status of the encryption / decryption task within the callback interface to implement the functions of each callback interface; encapsulation module 220 is used to create an encapsulation class with state variables, which can return the state variables to the caller when the caller publishes an encryption / decryption task request. The encapsulation class contains a passing interface to provide the caller with the function and data for task cancellation; wrapping module 230 is used to create a wrapper class. The wrapper class uses a weak reference to wrap the encapsulation class and returns a member variable object of the encapsulation class to the caller, so that calling functions under different programming language architectures hold the same member variable object of the encapsulation class, realizing mutual calling of encapsulation class objects between different programming languages.
[0172] In another embodiment, the packaging module 230 includes an acquisition unit 231 and a judgment unit 232. The acquisition unit 231 is used to define member variables, establish a smart pointer that does not control the object's lifecycle, the smart pointer holds the encapsulation class, and assign values to the transfer interface within the encapsulation class using the constructor, and establish parameters to pass the transfer interface to the smart pointer as a managed object. The judgment unit 232 is used to determine whether the transfer interface object containing the cancellation function and / or the transfer interface object containing the query cancellation function has been released by the C++ layer.
[0173] As a preferred embodiment, in another embodiment, the functional module 210 includes a display unit 211 capable of displaying the pass interface contained within the encapsulation class to provide the caller with the function and data for task cancellation.
[0174] above Figure 3 The apparatus with encryption / decryption task cancellation functionality under the iOS platform in this application embodiment has been described from the perspective of modular functional entities. The following is a detailed description of the apparatus with encryption / decryption task cancellation functionality under the iOS platform in this application embodiment from the perspective of hardware processing. Please refer to... Figure 4 The device 300 with encryption / decryption task cancellation function under iOS platform recommended in this application embodiment is one example, including:
[0175] Input device 301, output device 302, processor 303, and memory 304 (where the number of processors 303 can be one or more). Figure 3 (Taking a processor 303 as an example). In some embodiments of this application, the input device 301, output device 502, processor 303, and memory 304 can be connected via a bus or other means, wherein... Figure 3 Taking the example of a connection between China and Israel via a bus.
[0176] Specifically, by calling the operation instructions stored in memory 304, processor 303 executes the following steps:
[0177] Create a task class that includes an encryption / decryption task request callback interface to enable the cancellation of encryption / decryption tasks;
[0178] Create a wrapper class with state variables, which contains a passable object to provide the caller with a task cancellation command interface and / or a data interface.
[0179] Create a wrapper class and wrap the wrapper class so that calling functions under different programming language architectures hold the same wrapper class object, enabling mutual calling of objects between different programming languages.
[0180] By calling the operation instructions stored in memory 304, processor 303 is also used to execute... Figure 1 and Figure 2 Any of the methods in the corresponding embodiments.
[0181] like Figure 5 The diagram shown is a schematic representation of an embodiment of the electronic device provided in this application.
[0182] In another embodiment, the present invention also provides an electronic device including a memory 410, a processor 420, and a computer program 411 stored in the memory 410 and executable on the processor 420, wherein the processor 420 executes the computer program 411 to perform the following steps.
[0183] Create a task class that includes an encryption / decryption task request callback interface to enable the cancellation of encryption / decryption tasks;
[0184] Create a wrapper class with state variables, which contains a passable object to provide the caller with a task cancellation command interface and / or a data interface.
[0185] Create a wrapper class and wrap the wrapper class so that calling functions under different programming language architectures hold the same wrapper class object, enabling mutual calling of objects between different programming languages.
[0186] In practical implementation, when the processor 420 executes the computer program 411, it can achieve... Figure 1 Any of the corresponding implementation methods in the embodiments.
[0187] Since the electronic device described in this embodiment is a device used to implement the device with encryption / decryption task cancellation function under iOS platform in the embodiments of this application, those skilled in the art can understand the specific implementation method and various variations of the electronic device in this embodiment based on the method described in the embodiments of this application. Therefore, how the electronic device implements the method in the embodiments of this application will not be described in detail here. Any device used by those skilled in the art to implement the method in the embodiments of this application is within the scope of protection of this application.
[0188] Please see Figure 6 , Figure 6 This is a schematic diagram illustrating an embodiment of a computer-readable storage medium provided in this application.
[0189] like Figure 6 As shown, this embodiment provides a computer-readable storage medium 500 on which a computer program 511 is stored. When the computer program 511 is executed by a processor, it performs the following steps:
[0190] Create a task class that includes an encryption / decryption task request callback interface to enable the cancellation of encryption / decryption tasks;
[0191] Create a wrapper class with state variables, which contains a passable object to provide the caller with a task cancellation command interface and / or a data interface.
[0192] Create a wrapper class and wrap it so that calling functions in different programming language architectures hold the same object of the wrapper class, enabling mutual calling between different programming languages by passing objects.
[0193] In practical implementation, when the computer program 511 is executed by the processor, it can achieve the following: Figure 1-2 Any of the corresponding implementation methods in the embodiments.
[0194] It should be noted that the descriptions of each embodiment in the above embodiments have different focuses. For parts that are not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0195] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0196] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create a machine for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0197] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0198] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0199] This application also provides a computer program product, which includes computer software instructions that, when executed on a processing device, cause the processing device to perform actions such as... Figure 1-2 The process flow in the wind farm digital platform design method in the corresponding embodiment.
[0200] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a server or data center that integrates one or more available media. The available medium may be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state disk (SSD)).
[0201] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0202] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection between apparatuses or units through some interfaces, and may be electrical, mechanical, or other forms.
[0203] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0204] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0205] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0206] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.< / thandle> < / thandle> < / thandle> < / thandle> < / thandle> < / thandle> < / thandle> < / thandle> < / thandle> < / thandle> < / thandle> < / thandle> < / thandle> < / bool> < / bool>
Claims
1. A method for canceling encryption / decryption tasks on the iOS platform, characterized in that, include: Create a task class that includes an encryption / decryption task request callback interface to enable the cancellation of encryption / decryption tasks; Create a wrapper class with state variables, which contains a pass object to provide the caller with a task cancellation command interface and / or a data interface; Create a wrapper class and wrap the wrapper class so that calling functions under different programming language architectures hold the same wrapper class object, thereby enabling mutual calling of objects between different programming languages; The creation process of the wrapper class includes: Define member variables and establish weak reference smart pointers that do not control the lifecycle of objects. The weak reference smart pointers hold the wrapper class and use the passed objects in the wrapper class as managed objects. Construct an assignment function to assign a value to the passed object within the encapsulated class, and establish parameters to pass the assigned object to the weak reference smart pointer; Establish a cancellation interface and use the weak reference smart pointer to detect whether the passed object has been released by the C++ layer. If it has not been released, execute the cancellation task. Establish a query cancellation interface and use the weak reference smart pointer to detect whether the passed object has been released by the C++ layer. If it has not been released, execute the query cancellation task. The methods for canceling encryption / decryption tasks on the iOS platform also include: When a caller submits a request to cancel an encryption / decryption task through the cancellation command interface and / or by querying the cancellation command interface, the C++ layer returns a handle to a cancellation task object, which then calls the corresponding task callback interface to execute the cancellation function. The interface construction process for canceling the task object handle in the C++ layer includes: Establish a reference-counting smart pointer, which holds the passed object within the encapsulation class and is capable of creating and destroying the passed object; Establish a shared pointer to the encapsulated class and return a corresponding weak reference smart pointer management object to the caller; When the weak reference smart pointer is returned to the caller, a copy operation is used to return it, so that the C++ layer and the caller use the same passed object.
2. The method for canceling encryption / decryption tasks on the iOS platform according to claim 1, characterized in that, The creation process of the task class includes: Within the callback interface, parameters representing the execution result and task status of the encryption / decryption task are created to implement the functionality of each callback interface; The callback interfaces include callback interfaces for successful encryption / decryption, callback interfaces for encryption / decryption errors, and callback interfaces for actual task cancellation; and Create a state set for the task state parameters, the state set containing a state code that marks the task state; The status code indicates the execution result and status of the encryption / decryption task, and includes one or more of the following: encryption / decryption task in progress, generating encryption / decryption key, preparing encryption / decryption data, encrypting data, decrypting data, task cancelled, task successful, and task cancelled.
3. The method for canceling encryption / decryption tasks on the iOS platform according to claim 1 or 2, characterized in that, The creation process of the encapsulated class includes: Construct a wrapper function; A cancellation command interface is set within the encapsulated class, allowing the caller to cancel the encryption / decryption task through this interface. A cancellation command query interface is set within the encapsulation class, allowing the caller to query the cancellation command for the encryption / decryption task. The cancellation command interface includes status variables, which are Boolean atomic variables and include cancellation status variables and non-cancellation status variables.
4. The method for canceling encryption / decryption tasks on the iOS platform according to claim 1, characterized in that, It also includes checking and verifying the encryption / decryption task cancellation status parameters, which is achieved through the following steps: Create a review class and use the object to be passed when the decryption task is canceled, the status corresponding to the cancellation of the decryption task, and the task callback object as member variables; Establish an object constructor and check whether the object to which the decryption task was cancelled was internally cancelled. If cancelled, the callback task is cancelled, the corresponding status parameter is passed in, and the caller is notified.
5. An electronic device comprising an application processor and a memory, characterized in that, The processor is used to implement the steps of the encryption / decryption task cancellation method under the iOS platform as described in any one of claims 1-4 when implementing the computer management program stored in the memory.
6. A computer-readable storage medium storing computer management programs thereon, characterized in that, When the computer management program is executed by the processor, it implements the steps of the method for canceling encryption / decryption tasks on the iOS platform as described in any one of claims 1-4.
Citation Information
Patent Citations
Distribution and processing method and system for long-connection network data in IOS system
CN108696537A
