Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

The clearest way into the Universe is through a forest wilderness. -- John Muir


devel / comp.lang.ada / Help with designing data structure for novice Ada programmer

SubjectAuthor
* Help with designing data structure for novice Ada programmerAleksy Grabowski
`* Re: Help with designing data structure for novice Ada programmerPaul Rubin
 +* Re: Help with designing data structure for novice Ada programmerAleksy Grabowski
 |`- Re: Help with designing data structure for novice Ada programmerDmitry A. Kazakov
 `* Re: Help with designing data structure for novice Ada programmer1.AAC0832
  `* Re: Help with designing data structure for novice Ada programmerDennis Lee Bieber
   `- Re: Help with designing data structure for novice Ada programmerDmitry A. Kazakov

1
Help with designing data structure for novice Ada programmer

<srcstm$1k0$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=6517&group=comp.lang.ada#6517

 copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: hur...@gmail.com (Aleksy Grabowski)
Newsgroups: comp.lang.ada
Subject: Help with designing data structure for novice Ada programmer
Date: Sat, 8 Jan 2022 21:41:26 +0100
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <srcstm$1k0$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 8 Jan 2022 20:41:26 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ada32d08fc4d17bff0f383df6d203fd1";
logging-data="1664"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19M+muCQOBjCYvKWdKA1WJp"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:96.0) Gecko/20100101
Thunderbird/96.0
Cancel-Lock: sha1:L2kYUz7l8Ni0PtzzkeRkwTQ5O8s=
Content-Language: en-US
 by: Aleksy Grabowski - Sat, 8 Jan 2022 20:41 UTC

Hi all, I'm new here.

I'm experienced embedded C developer and I've started 2 years ago an
implementation of one of the specifications kind of popular in the
payment industry. I also hope to make it open source one day.

I've implemented most of it in C, but now I have a problem, because I
have to guarantee consistency of a huge configurable data structure,
that can be changed by an entity which in theory may not be in my
control. And adding all checks quickly became nightmarish and then I've
found an Ada language.

I already did some experiments, but it doesn't look right, because my
experience in Ada is around 1 week. And I want to quickly assess if it
is worth doing at all.

So my requirements:

1. Important: Syntax to accessing, setting, comparing, allocating
values should be as simple as possible, because the body of code is
generated from diagrams and it should be understandable by a non
programmer, ie payments expert. In C I've wrote some macros for it.
2. Memory management should be unobtrusive to the visual look of
diagrams. In C I've used a memory pool, so I just have to do a
single de-allocation after each transaction.
3. It should support optional, mandatory and conditional fields. In C
modeled as pointers.
4. It should support bit fields that may have different meaning if some
flag is set (in C a union of bitfields)
5. Consistency between elements, if a particular flag is set to True
then some other fields must have a certain value as well. Probably
doable by Dynamic_Predicate.
6. Data elements should be accessible by name `db.processingStatus' or
by it's tag value like `db (16#CA#)' and also it should support any
additional tag that can be supplied by the card, even if its
symbolic name isn't known (in C it's void*).
7. I have to guarantee consistency of a different views of the same
value eg. amount represented as BCD array – usual representation
or 32 bit unsigned integer when requested by tag 16#81#.
8. It should be possible to modify data elements both symbolically or
using binary arrays with encoded data. Either because it is
specified this way or I have to set it to the unspecified value. In
C I've achieved this by having a union of char[] and a bitfield.
9. And as a bonus it should be serializable to EMV's variant of TLV
which isn't the same as you have in ASN.1, because EMV specification
was standardized before ASN.1 BER and those committees had little to
no cooperation.

I'm asking Ada wizards if it is at all doable in Ada? Or maybe some
links to opensource project where something similar was already achieved
so I can look it up?

--
Best Regards,
Alex

P.S. My code is available on github if someone is interested.

Re: Help with designing data structure for novice Ada programmer

<87sftx1vpd.fsf@nightsong.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=6520&group=comp.lang.ada#6520

 copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: no.em...@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.ada
Subject: Re: Help with designing data structure for novice Ada programmer
Date: Sat, 08 Jan 2022 18:36:46 -0800
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <87sftx1vpd.fsf@nightsong.com>
References: <srcstm$1k0$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="0df76f9e7d74b006453fc41ace66f4ec";
logging-data="1851"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX187MHmVM5xTub/9q+GJujyi"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:q4qKpTb5++EqYC24HSqJdr0ZCv0=
sha1:2leOJ4KHjtriO6iqn7H83V6+yJM=
 by: Paul Rubin - Sun, 9 Jan 2022 02:36 UTC

Aleksy Grabowski <hurufu@gmail.com> writes:
> I'm experienced embedded C developer and I've started 2 years ago an
> implementation of one of the specifications kind of popular in the
> payment industry. I also hope to make it open source one day.

Can you say what specification it is?

> have to guarantee consistency of a huge configurable data structure,
> that can be changed by an entity which in theory may not be in my
> control. And adding all checks quickly became nightmarish and then I've
> found an Ada language.

It sounds like you waht to define a datatype for this structure, with
access and update procedures (OOP is not necessary but it's the same
idea) that make sure all the rules are followed. Is there more to it
than that?

Ada sounds like a reasonable choice, C sounds terrible, other
possibilities depend on the hardware and software environment. Would
this have to run on a smart card cpu or anything like that?

Re: Help with designing data structure for novice Ada programmer

<sreb3f$g0e$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=6521&group=comp.lang.ada#6521

 copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: hur...@gmail.com (Aleksy Grabowski)
Newsgroups: comp.lang.ada
Subject: Re: Help with designing data structure for novice Ada programmer
Date: Sun, 9 Jan 2022 10:49:35 +0100
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <sreb3f$g0e$1@dont-email.me>
References: <srcstm$1k0$1@dont-email.me> <87sftx1vpd.fsf@nightsong.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 9 Jan 2022 09:49:35 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="7246112190663a2a5aae7c1f00952642";
logging-data="16398"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1907v+fNXr13wqqJLnD+yna"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:96.0) Gecko/20100101
Thunderbird/96.0
Cancel-Lock: sha1:f7OzVFbOuNO7tjYpvyKmudVIXu0=
In-Reply-To: <87sftx1vpd.fsf@nightsong.com>
Content-Language: en-US
 by: Aleksy Grabowski - Sun, 9 Jan 2022 09:49 UTC

First of all thanks for an answer.

On 1/9/22 03:36, Paul Rubin wrote:
> Can you say what specification it is?

Yeah sure, it's called nexo. It is an open specification and it is
available for free after a registration on nexo-standards.org. It is
basically a high level description of an abstract payment terminal. They
specify all the data structures and full flow of control. Basically they
try to combine all EMV books and all regional payment schemes into a one
huge beast, to make a universal terminal.

> It sounds like you waht to define a datatype for this structure, with
> access and update procedures (OOP is not necessary but it's the same
> idea) that make sure all the rules are followed. Is there more to it
> than that?

Something more. The first thing is update procedures, Right now I have
two modules trusted and non-trusted. Trusted part just does whatever it
wants to and non-trusted uses geters and setters. But the other thing is
that I want to model data as close to the spec as possible, so if it is
set to update some enum to a value 16#3F00# I do this. The another part
is because they tried to unify the whole payment zoo into single spec
there a lot of bizarre things there.

I also have some concrete question, how to properly implement optional
element? Right now I have something like this:

generic
type T is private;
package TypeUtils is
type Optional(exists : Boolean) is
record
case exists is
when True => value : T;
when False => null;
end case;
end record;
end TypeUtils;

But it looks like it doesn't work, because it depends on the
discriminant `exists' but it is set once in .ads file and I can't modify
it in runtime.

> Ada sounds like a reasonable choice, C sounds terrible, other
> possibilities depend on the hardware and software environment. Would
> this have to run on a smart card cpu or anything like that?

Not really, arm CPU is enough. The one I have is MAX32590. I'm also not
really worried about memory consumption. Those embedded platforms have a
plenty of RAM nowadays.

How large this project can be? I'm already two years into it :)

Re: Help with designing data structure for novice Ada programmer

<srecbf$1rpv$1@gioia.aioe.org>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=6522&group=comp.lang.ada#6522

 copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!yWEAdf48JK7zWb9n7RvSRA.user.46.165.242.91.POSTED!not-for-mail
From: mail...@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: Help with designing data structure for novice Ada programmer
Date: Sun, 9 Jan 2022 11:10:55 +0100
Organization: Aioe.org NNTP Server
Message-ID: <srecbf$1rpv$1@gioia.aioe.org>
References: <srcstm$1k0$1@dont-email.me> <87sftx1vpd.fsf@nightsong.com>
<sreb3f$g0e$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="61247"; posting-host="yWEAdf48JK7zWb9n7RvSRA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.1
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Dmitry A. Kazakov - Sun, 9 Jan 2022 10:10 UTC

On 2022-01-09 10:49, Aleksy Grabowski wrote:

> I also have some concrete question, how to properly implement optional
> element? Right now I have something like this:
>
>     generic
>         type T is private;
>     package TypeUtils is
>         type Optional(exists : Boolean) is
>         record
>             case exists is
>                 when True => value : T;
>                 when False => null;
>             end case;
>         end record;
>     end TypeUtils;
>
> But it looks like it doesn't work, because it depends on the
> discriminant `exists' but it is set once in .ads file and I can't modify
> it in runtime.

Provide a default value for the discriminant:

type Optional (Defined : Boolean := False) is record
case Present is
when True =>
Value : T;
when False =>
null;
end case;
end record;

Now it is a definite type and you can place it into another record type:

type Container is record
...
Optional_Field : Optional;
...
end record;

and you can always update it:

X : Container;

X.Optional_Field := (True, Value_1);
...
X.Optional_Field := (Defined => False);
...
X.Optional_Field := (True, Value_2);
...

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: Help with designing data structure for novice Ada programmer

<a4WdnVvY4Zs-nnz8nZ2dnUU7-WfNnZ2d@earthlink.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=6532&group=comp.lang.ada#6532

 copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!news.swapon.de!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!buffer2.nntp.dca1.giganews.com!buffer1.nntp.dca1.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail
NNTP-Posting-Date: Thu, 13 Jan 2022 23:01:23 -0600
Subject: Re: Help with designing data structure for novice Ada programmer
Newsgroups: comp.lang.ada
References: <srcstm$1k0$1@dont-email.me> <87sftx1vpd.fsf@nightsong.com>
From: z24ba7....@nowhere (1.AAC0832)
Date: Fri, 14 Jan 2022 00:01:22 -0500
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
Thunderbird/68.12.0
MIME-Version: 1.0
In-Reply-To: <87sftx1vpd.fsf@nightsong.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
Message-ID: <a4WdnVvY4Zs-nnz8nZ2dnUU7-WfNnZ2d@earthlink.com>
Lines: 38
X-Usenet-Provider: http://www.giganews.com
NNTP-Posting-Host: 98.77.165.67
X-Trace: sv3-bKomZe38kI5gcIZxdyL44Dlb8GFE7JyxeV7MTsVl20tiaEvB5VdyZrvHew6srOcG05f5bSWcJsZNwfo!kldBUjGLUdBMyLKUxPEYKbq/U0vXD8N8aaHZJB1Xm4Ax4VqgueaRLY7rxUAEtdYiAXYixRtFE5xI!rmXRajqso9plgtDsaRE=
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 2955
 by: 1.AAC0832 - Fri, 14 Jan 2022 05:01 UTC

On 1/8/22 9:36 PM, Paul Rubin wrote:
> Aleksy Grabowski <hurufu@gmail.com> writes:
>> I'm experienced embedded C developer and I've started 2 years ago an
>> implementation of one of the specifications kind of popular in the
>> payment industry. I also hope to make it open source one day.
>
> Can you say what specification it is?
>
>> have to guarantee consistency of a huge configurable data structure,
>> that can be changed by an entity which in theory may not be in my
>> control. And adding all checks quickly became nightmarish and then I've
>> found an Ada language.
>
> It sounds like you waht to define a datatype for this structure, with
> access and update procedures (OOP is not necessary but it's the same
> idea) that make sure all the rules are followed. Is there more to it
> than that?
>
> Ada sounds like a reasonable choice, C sounds terrible, other
> possibilities depend on the hardware and software environment. Would
> this have to run on a smart card cpu or anything like that?

Having just implemented a small app using interlinked
doubly-linked lists that are allocated on demand, Ada
can do at least that much quite easily and cleanly without
any OOP BS. "Records"/"Structs" are much as in Pascal,
but they don't call pointers "pointers" :-)

You DO have to bring in a special proc to FREE memory allocated
on the heap however. Kinda weird - you'd think making and freeing
would naturally be implemented together. This "free()" is very
type-specific, multiple incarnation of the proc will be needed
if you have multiple kinds of records to free.

The other (extensive) requirements ... I'll leave that to the
more experienced.

(am I off one level here ?)

Re: Help with designing data structure for novice Ada programmer

<jj73ug5cv48bq7cl6h3te37e2t6n9gugt1@4ax.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=6533&group=comp.lang.ada#6533

 copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!buffer2.nntp.dca1.giganews.com!buffer1.nntp.dca1.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Fri, 14 Jan 2022 10:05:32 -0600
From: wlfr...@ix.netcom.com (Dennis Lee Bieber)
Newsgroups: comp.lang.ada
Subject: Re: Help with designing data structure for novice Ada programmer
Date: Fri, 14 Jan 2022 11:05:33 -0500
Organization: IISS Elusive Unicorn
Message-ID: <jj73ug5cv48bq7cl6h3te37e2t6n9gugt1@4ax.com>
References: <srcstm$1k0$1@dont-email.me> <87sftx1vpd.fsf@nightsong.com> <a4WdnVvY4Zs-nnz8nZ2dnUU7-WfNnZ2d@earthlink.com>
User-Agent: ForteAgent/8.00.32.1272
X-No-Archive: yes
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Lines: 20
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-6pWa5hqa/OS8aG9t/NUJcMvFz7Ybx2nYG3WwkaXS9wK2+9fdU7cJ9GrJTMnsbzczo6FHvh3cTrNmG/n!gX7oAZoNJoYeCrDAd8zrkS6qWeqGeEdaJ75Kf0Ni6NprIMhzjPC5geeIZt/1KTNZI8nsnYPv
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 2077
 by: Dennis Lee Bieber - Fri, 14 Jan 2022 16:05 UTC

On Fri, 14 Jan 2022 00:01:22 -0500, "1.AAC0832" <z24ba7.net> declaimed the
following:

> You DO have to bring in a special proc to FREE memory allocated
> on the heap however. Kinda weird - you'd think making and freeing
> would naturally be implemented together. This "free()" is very
> type-specific, multiple incarnation of the proc will be needed
> if you have multiple kinds of records to free.
>
Take into account the origins for Ada. Many embedded/real-time
applications follow the practice of pre-allocating all memory during
application initialization before transitioning into "running" mode. They
never deallocate memory. If something goes wrong, the entire application
system is rebooted, resetting all memory.

--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/

Re: Help with designing data structure for novice Ada programmer

<srsci5$s4e$1@gioia.aioe.org>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=6534&group=comp.lang.ada#6534

 copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!yWEAdf48JK7zWb9n7RvSRA.user.46.165.242.91.POSTED!not-for-mail
From: mail...@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: Help with designing data structure for novice Ada programmer
Date: Fri, 14 Jan 2022 18:40:22 +0100
Organization: Aioe.org NNTP Server
Message-ID: <srsci5$s4e$1@gioia.aioe.org>
References: <srcstm$1k0$1@dont-email.me> <87sftx1vpd.fsf@nightsong.com>
<a4WdnVvY4Zs-nnz8nZ2dnUU7-WfNnZ2d@earthlink.com>
<jj73ug5cv48bq7cl6h3te37e2t6n9gugt1@4ax.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="28814"; posting-host="yWEAdf48JK7zWb9n7RvSRA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Dmitry A. Kazakov - Fri, 14 Jan 2022 17:40 UTC

On 2022-01-14 17:05, Dennis Lee Bieber wrote:
> On Fri, 14 Jan 2022 00:01:22 -0500, "1.AAC0832" <z24ba7.net> declaimed the
> following:
>
>
>> You DO have to bring in a special proc to FREE memory allocated
>> on the heap however. Kinda weird - you'd think making and freeing
>> would naturally be implemented together. This "free()" is very
>> type-specific, multiple incarnation of the proc will be needed
>> if you have multiple kinds of records to free.
>>
> Take into account the origins for Ada. Many embedded/real-time
> applications follow the practice of pre-allocating all memory during
> application initialization before transitioning into "running" mode. They
> never deallocate memory. If something goes wrong, the entire application
> system is rebooted, resetting all memory.

They may use some special management of resources that do not involve
heap and explicit deallocation. E.g. a linked list can be allocated in
an arena. There would be no free(), the whole list gets killed when the
arena is erased.

The arena itself may sit in a local/static storage array or a
pre-allocated upon start array.

Ada provides user memory pools for that kind of implementations. As an
example consider a network protocol implementation. There would be a
fixed-size storage per connection where entities of an incoming packet
are stored upon parsing it. After processing the packet the storage is
emptied.

No buffer overflow or network attacks possible. If the packet has too
much data, Storage_Error is propagated from new and the connection gets
dropped.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

1
server_pubkey.txt

rocksolid light 0.9.7
clearnet tor