-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #567 from ballerina-platform/pgp-files
[Update 11 Feature] Add support for PGP encryption/decryption with streams
- Loading branch information
Showing
22 changed files
with
1,011 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright (c) 2024 WSO2 LLC. (https://www.wso2.com). | ||
// | ||
// WSO2 LLC. licenses this file to you under the Apache License, | ||
// Version 2.0 (the "License"); you may not use this file except | ||
// in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
import ballerina/jballerina.java; | ||
|
||
class DecryptedStreamIterator { | ||
boolean isClosed = false; | ||
|
||
public isolated function next() returns record {|byte[] value;|}|Error? { | ||
byte[]|Error? bytes = self.readDecryptedStream(); | ||
if bytes is byte[] { | ||
return {value: bytes}; | ||
} else { | ||
return bytes; | ||
} | ||
} | ||
|
||
public isolated function close() returns Error? { | ||
if !self.isClosed { | ||
var closeResult = self.closeDecryptedStream(); | ||
if closeResult is () { | ||
self.isClosed = true; | ||
} | ||
return closeResult; | ||
} | ||
return; | ||
} | ||
|
||
isolated function readDecryptedStream() returns byte[]|Error? = @java:Method { | ||
'class: "io.ballerina.stdlib.crypto.nativeimpl.StreamUtils" | ||
} external; | ||
|
||
isolated function closeDecryptedStream() returns Error? = @java:Method { | ||
'class: "io.ballerina.stdlib.crypto.nativeimpl.StreamUtils" | ||
} external; | ||
} | ||
|
||
class EncryptedStreamIterator { | ||
boolean isClosed = false; | ||
|
||
public isolated function next() returns record {|byte[] value;|}|Error? { | ||
byte[]|Error? bytes = self.readEncryptedStream(); | ||
if bytes is byte[] { | ||
return {value: bytes}; | ||
} else { | ||
return bytes; | ||
} | ||
} | ||
|
||
public isolated function close() returns Error? { | ||
if !self.isClosed { | ||
var closeResult = self.closeEncryptedStream(); | ||
if closeResult is () { | ||
self.isClosed = true; | ||
} | ||
return closeResult; | ||
} | ||
return; | ||
} | ||
|
||
isolated function readEncryptedStream() returns byte[]|Error? = @java:Method { | ||
'class: "io.ballerina.stdlib.crypto.nativeimpl.StreamUtils" | ||
} external; | ||
|
||
isolated function closeEncryptedStream() returns Error? = @java:Method { | ||
'class: "io.ballerina.stdlib.crypto.nativeimpl.StreamUtils" | ||
} external; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
Ballerina is an open-source programming language designed for cloud-native application development. It combines features for integration, service orchestration, and network interaction, with a focus on ease of use for building APIs, managing data, and deploying in distributed environments. Ballerina's syntax and built-in concurrency support make it well-suited for creating robust, scalable, and secure services. | ||
|
||
Ballerina adopts a developer-friendly approach by incorporating modern programming constructs, such as structural typing, flexible JSON handling, and a familiar C-style syntax, which reduces the learning curve for developers. The language has first-class support for network primitives, allowing developers to directly work with network protocols like HTTP, WebSockets, and gRPC without the need for additional libraries. This direct handling of network interactions makes Ballerina ideal for writing microservices and integrating with other systems effortlessly. | ||
|
||
Ballerina also features built-in support for distributed transactions, reliable messaging, and data transformations, making it suitable for integration-heavy applications. Its built-in observability tools, including metrics, logs, and distributed tracing, help developers monitor and debug applications efficiently. Ballerina is inherently cloud-native, with easy containerization and Kubernetes deployment support, simplifying the process of deploying services in modern cloud environments. | ||
|
||
The concurrency model in Ballerina is based on the concept of "strands," which are lightweight threads managed by the language runtime. This model allows developers to write concurrent code using simple constructs, such as asynchronous functions and workers, without worrying about low-level threading concerns. This makes it easier to develop applications that are responsive and scalable, capable of handling high loads and concurrent user interactions. | ||
|
||
Ballerina’s ecosystem includes various tools, such as the Ballerina Central registry, which provides a platform for sharing and discovering packages. The language’s visual representation of code through sequence diagrams is another unique feature, enabling both developers and non-developers to better understand program behavior, especially for integration logic. Ballerina's compiler can generate these diagrams automatically, which is beneficial for documentation and analysis of workflows. | ||
|
||
Furthermore, Ballerina's support for data-oriented programming makes it easy to transform and manipulate structured data formats like JSON, XML, and SQL. This, along with the language’s built-in type system that directly represents these data types, reduces the need for complex data mapping and serialization tasks. With support for RESTful APIs, GraphQL, and multiple database connectors, Ballerina is designed to provide seamless integration capabilities, making it an excellent choice for businesses looking to modernize their IT landscape with cloud-native services. |
Oops, something went wrong.