Non readable - YANG - ietf-netmod-yang

There is a way to define non readable data in yang?
module system{
leaf name{
type string;
}
leaf password{
type string;
}
}
So in this case 'password' is the non readable data.

If you wish to make the data "unreadable", you can use binary built-in type, which enables you to set an arbitrary blob of bytes (base64 encoded) as the value for a leaf. Encrypted bytes included.
leaf password {
type binary;
default "cGFzc3dvcmQ="; // <-- plain text "password"
}

Related

Ethers how to encode data to bytes parameters

I'm trying to test a piece of generic solidity code, I'm trying to figure out how to encode data properly for bytes parameters.
I have a function in a smart contract which looks like so:
function validateAdditionalCalldata(bytes calldata resolverOptions) external view;
function resolve(uint256 amountIn, bytes calldata resolverOptions) public override returns (uint256 amountOut) {
// Decode the additional calldata as a SwapResolverOptions struct
(SwapResolverOptions memory swapResolverOptions) = abi.decode(resolverOptions, (SwapResolverOptions));
return resolveImplementation(amountIn, swapResolverOptions);
}
This solidity code will generate code which takes in a PromiseOrValue<BytesLike>:
resolve(
amountIn: PromiseOrValue<BigNumberish>,
resolverOptions: PromiseOrValue<BytesLike>,
overrides?: Overrides & { from?: PromiseOrValue<string> }
): Promise<ContractTransaction>;
export type SwapResolverOptionsStruct = {
path: PromiseOrValue<BytesLike>;
deadline: PromiseOrValue<BigNumberish>;
amountIn: PromiseOrValue<BigNumberish>;
amountOutMinimum: PromiseOrValue<BigNumberish>;
inputTokenAddress: PromiseOrValue<string>;
targetAddress: PromiseOrValue<string>;
destinationAddress: PromiseOrValue<string>;
};
I'm wondering how I can encode a specific parameter so I can pass it along to ethers. In typescript I have a set of options that looks like this:
const resolverOptions: SwapResolverOptionsStruct = {
path: '0x00',
//This parameter will be removed in the next deployment
deadline: BigNumber.from(1000),
amountIn: BigNumber.from(100000000),
amountOutMinimum: BigNumber.from(0),
inputTokenAddress: WMATIC_MUMBAI,
destinationAddress: owner.address,
targetAddress: ADDRESS_ZERO,
};
I'm trying to encode this parameters in the following way:
import { defaultAbiCoder } from "#ethersproject/abi";
encodedResolverOptions = defaultAbiCoder.encode(
['SwapResolverOptionsStruct'],
[resolverOptions]
);
However when I try to encode it gets and error:
Error: invalid type (argument="type", value="SwapResolverOptionsStruct",
Note: in my paticular use case I cannot just encoded the whole function call.
I would like to pass my data to the validateAdditionalCalldata how ever the parameter is PromiseOrValue<BytesLike>
How can I encoded my resolverOptions so I can pass it as bytes?
I figured out a few way to do this. I'll list each one:
Resolve the type params using ethers and get function. (if there is a function which has your type in it)
const functionFragment = swapResolverInterface.getFunction("resolveImplementation");
encodedResolverOptions = defaultAbiCoder.encode(
[functionFragment.inputs[1]],
[resolverOptions]
);
Resolve it from an object and a method signature with parameter names:
encodedResolverOptions = defaultAbiCoder.encode(
["(bytes path,uint256 deadline,uint256 amountIn,uint256 amountOutMinimum,address inputTokenAddress,address destinationAddress,address targetAddress)"],
[resolverOptions]
);
Resolve it as an array from the method signature without names Note: this assumes the object was declared in the same order as the parameters, alternatively you can manually construct the array:
encodedResolverOptions = defaultAbiCoder.encode(
["(bytes,uint256,uint256,uint256,address,address,address)"],
[Object.values(resolverOptions)]
);

encoding and decoding base64.in aws appsync resolver

I have a resolver that receives an argument "nextToken" ($ctx.args.nextToken) which will be in base64 string. In the request mapping template, I need to convert nextToken from base64 string into ascii string. I know that Appsync has $util.base64Decode(String) : byte[] but this function gives back byte[] but I want back an ascii string.
In addition, I will need to create base64 string from ascii string in the response mapping template. Again Appsync provides a function $util.base64Encode( byte[] ) : String but I don't know how to change my ascii string into byte[].
Anybody has any idea how to handle both situations. Thanks in advance.
VTL template $util functions for base64 accept a string and return a string.
Example VTL template:
#set($base64 = $util.base64Encode("Hello World"))
{
"label": "$util.base64Decode($base64)"
}
Returns "Hello World"

Get nested object in structure in gorm

I have two structures:
type GoogleAccount struct {
Id uint64
Token string
}
It represent my custom PostgreSQL object type (i created myself):
CREATE TYPE GOOGLE_ACCOUNT AS
(
id NUMERIC,
token TEXT
);
And next structure is table in DB:
type Client struct {
IdClient uint64 `gorm:"primary_key"`
Name string
PhotoUrl string
ApprovalNumber uint16
Phone string
Password string
HoursOfNotice int8
Google GoogleAccount
}
And my custom object nested in type Client and named as google. I've tried to read data by the next way:
var users model.Client
db.First(&users)
But unfortunately I can't read field google (have a default value). I don't want to create separate table with google_account, or make this structure as separated fields in client table or packed it as json (created separate entity, because this structure used not only in this table and I'm searching new ways, that get the same result, but more gracefully). The task is not to simplify the presentation of data in the table. I need to make the correct mapping of the object from postgres to the entity.
Right now I found one solution - implement Scanner to GoogleAccount. But value in the input method is []uint8. As I can suppose, []uint8 can cast to string, and after that I can parse this string. This string (that keep in db) look like (x,x) - where x - is value. Is the right way, to parse string and set value to object? Or is way to get this result by ORM?
Is the possible way, to read this data as nested structure object?
It looks like you'll want to do two things with what you have: (1) update the model so you have the right relationship binding, and (2) use the .Preload() method if you're trying to get it to associate the data on read.
Model Changes
Gorm automatically infers relationships based on the name of the attributes in your struct and the name of the referenced struct. The problem is that Google attribute of type GoogleAccount isn't associating because gorm is looking for a type Google struct.
You're also missing a foreign key on GoogleAccount. How would the ORM know which GoogleAccount to associate with which Client? You should add a ClientId to your GoogleAccount struct definition.
Also, I would change the primary keys you're using to type uint since that's what gorm defaults to (unless you have a good reason not to use it)
If I were you, I would change my struct definitions to the following:
type Client struct {
IdClient uint `gorm:"primary_key"`
Name string
PhotoUrl string
ApprovalNumber uint16
Phone string
Password string
HoursOfNotice int8
GoogleAccount GoogleAccount // Change this to `GoogleAccount`, the same name of your struct
}
type GoogleAccount struct {
Id uint
ClientId uint // Foreign key
Token string
}
For more information on this, take a look at the associations documentation here: http://gorm.io/associations.html#has-one
Preloading associations
Now that you actually have them properly related, you can .Preload() get the nested object you want:
db.Preload("GoogleAccount").First(&user)
Using .Preload() will populate the user.GoogleAccount attribute with the correctly associated GoogleAccount based on the ClientId.
For more information on this, take a look at the preloading documentation: http://gorm.io/crud.html#preloading-eager-loading
Right now I found one solution - implement Scanner to GoogleAccount. At input of the Scan method I got []uint8, that I cast to string and parse in the end. This string (that keeping in db) look like (x,x) - where x - is value. Of course, it is not correct way to achieve my goal. But I couldn't found other solution.
I highly recommended use classical binding by relationship or simple keeping these fields in table as simplest value (not as object).
But if you would like to experiment with nested object in table, you can look at my realization, maybe it would be useful for you:
type Client struct {
// many others fields
Google GoogleAccount `json:"google"`
}
type GoogleAccount struct {
Id uint64 `json:"id"`
Token string `json:"token"`
}
func (google GoogleAccount) Value() (driver.Value, error) {
return "(" + strconv.FormatUint(google.Id, 10) + "," + google.Token + ")", nil
}
func (google *GoogleAccount) Scan(value interface{}) error {
values := utils.GetValuesFromObject(value)
google.Id, _ = strconv.ParseUint(values[0], 10, 64)
google.Token = values[1]
return nil
}

Can a Key String in properties file become a variable in another Key String (GWT)?

in Gwt, we can set message constants at properties file like this
passWordErr={0} must contain Upper case
passWordBox=Please enter {0} Here. {0} must contain Upper case
in the interface MyMessages, we have:
public interface MyMessages extends Messages{
String passWordErr (String field);
String passWordBox (String field);
}
As you can see, in the properties file we got the duplicated text "{0} must contain Upper case". So if we change it, we need to change in 2 places & that is not good.
So my question is:
Can a Key String in properties file become a variable in another Key String (GWT)?
Something like this:
passWordErr={0} must contain Upper case
passWordBox=Please enter {0} Here. + passWordErr({0})
No, you cannot do that. More importantly, there is no need to do that.
In your example, instead of
passWordErr={0} must contain upper case
passWordBox=Please enter {0} here. {0} must contain Upper case
it should be
passWordErr={0} must contain upper case.
passWordBox=Please enter {0} here.
Then, when you need to show a message, you can simply concatenate both messages:
Window.alert(myMessages.passWordBox("password") + " " + myMessages.passWordErr("password"));

How to pass a byte[] parameter type in a sql query in MyBatis?

I need to match against an encrypted column in the DB. I need to pass the encrypted value for matching as a byte[]. The hashcode of the byte[] is passed instead of the actual value stored in the byte[]. Because the hash code is passed, it does not match the value correctly. Below is my query and the function call in the Mapper.java.
AccBalNotificationBean selectAccBalNotificationBean(#Param("acctIdByteArray") byte[] acctIdByteArray);
SELECT toa.accounts_id from tbl_transactions_other_accounts toa WHERE other_account_number = #{acctIdByteArray}
Thank you for your help.
I assume the datatype of your other_account_number column is of type string (char, varchar etc). Mybatis will use the StringDataTypeHandler by default and call the .toString() method of your byte array. Give MyBatis a hint that you want the content of your array to be used, by specifying the typeHandler.
.. WHERE other_account_number = #{acctIdByteArray, typeHandler=org.apache.ibatis.type.ByteArrayTypeHandler}