comp.lang.ada
 help / color / mirror / Atom feed
* Re: ada and final/sealed classes
       [not found] <1c2f5137.0410130438.3ea08553@posting.google.com>
@ 2004-10-13 13:31 ` Dmitry A. Kazakov
  2004-10-17 15:36 ` Matthew Heaney
  2004-10-18  7:46 ` Martin Krischik
  2 siblings, 0 replies; 4+ messages in thread
From: Dmitry A. Kazakov @ 2004-10-13 13:31 UTC (permalink / raw)


On 13 Oct 2004 05:38:32 -0700, Hans Van den Eynden wrote:

> I want to prevent that someone inherits from a type I made (for
> security purposes).

1. When the public view of the type is untagged, then it is impossible to
extend it publicly:

package Foo is
   type Final is private;
   procedure Baz (Object : Final);
private
   type Final is tagged null record;

Only children of the package Foo know that Final is tagged. Therefore:

with Foo;
package Unrelated is
   type Illegal is new Foo.Final with null record; -- Error

2. A less brutal approach: a) The primitive operations can be made private;
b) other operations, especially class-wide ones, are always "final":

package Foo is
   type Has_Secret_Methods is tagged ...;
   procedure Final (Object : in out Has_Secret_Methods'Class);
private
   procedure Secret (Object : in out Has_Secret_Methods);

Here Final is a class-wide procedure. As such it cannot be overridden.
Secret is not visible for public clients and so cannot be overridden by
those.

3. For happy owners of ergonomic keyboards: you can always use aggregation.
However the language will not help you in creating wrappers, so train your
fingers:

package Private_Foo is
   type Unsealed is tagged ...;
   procedure Baz (X : Unsealed);
end Private_Foo;

with Private_Foo;
package Public_Foo is
   type Sealed is private; -- non-tagged wrapper
   procedure Baz (X : Sealed); -- Proxy
   pragma Inline (Baz);
private
   use Private_Foo;
   type Sealed is record
      Thing : Unsealed;
   end record;
----
   procedure Baz (X : Sealed) is
   begin
      Baz (X.Thing);
   end Baz;

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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ada and final/sealed classes
       [not found] <1c2f5137.0410130438.3ea08553@posting.google.com>
  2004-10-13 13:31 ` ada and final/sealed classes Dmitry A. Kazakov
@ 2004-10-17 15:36 ` Matthew Heaney
  2004-10-18  0:20   ` Brian May
  2004-10-18  7:46 ` Martin Krischik
  2 siblings, 1 reply; 4+ messages in thread
From: Matthew Heaney @ 2004-10-17 15:36 UTC (permalink / raw)


onsbomma@hotmail.com (Hans Van den Eynden) writes:

> I want to prevent someone from inheriting from a type I made (for
> security purposes). I am a junior Ada programmer and I know this
> possible in Java (final class) and C# (sealed class). Is this also
> possible in Ada???

Not really, no.

Ada is designed such that there is a lexical distinction for a type that
has visibility to the representation of another type.  

The way this works is that derived types in a class that have access to
the representation of the parent type must be declared in child
packages:

package P is
   type T is tagged limited private;
   ...
private
   type T is tagged limited record
     ... -- lots of secret stuff here
   end record;
end P;

package P.C is
   type NT is new T with private;
   ...
private
   type NT is new T with record
      ... -- more secret stuff here
   end record;
end P.C;

Here, type P.C.NT has visibility to the private presentation of type
P.T.  That fact is ennunciated since NT is declared in the same
subsystem (rooted at package P) as type T.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ada and final/sealed classes
  2004-10-17 15:36 ` Matthew Heaney
@ 2004-10-18  0:20   ` Brian May
  0 siblings, 0 replies; 4+ messages in thread
From: Brian May @ 2004-10-18  0:20 UTC (permalink / raw)


>>>>> "Matthew" == Matthew Heaney <matthewjheaney@earthlink.net> writes:

    Matthew> onsbomma@hotmail.com (Hans Van den Eynden) writes:
    >> I want to prevent someone from inheriting from a type I made (for
    >> security purposes). I am a junior Ada programmer and I know this
    >> possible in Java (final class) and C# (sealed class). Is this also
    >> possible in Ada???

    Matthew> Not really, no.

Also, Ada scoping rules were designed to prevent programming errors
from occurring when you accidently refer to a value without using the
correct interface.

Ada scoping rules were not designed to prevent an intruder from
deliberately doing malicious activities, as everything runs in the
same Unix process. Any security measures must be implemented by you,
the programmer. e.g. split into multiple, independent processes,
communicating via CORBA, SOAP, or some other protocol.

This is unlike Java, where everything runs in a secure sandbox, and it
is possible to check the code to ensure it doesn't break set rules.

Then again, I may have misunderstood what you are trying to do. I
can't see any security value in stopping someone from inheriting from
a type, as creating new types has to happen at compile time (unlike
Java), and if you have access to compile the code, you probably have
access to everything anyway.
-- 
Brian May <bam@snoopy.apana.org.au>



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ada and final/sealed classes
       [not found] <1c2f5137.0410130438.3ea08553@posting.google.com>
  2004-10-13 13:31 ` ada and final/sealed classes Dmitry A. Kazakov
  2004-10-17 15:36 ` Matthew Heaney
@ 2004-10-18  7:46 ` Martin Krischik
  2 siblings, 0 replies; 4+ messages in thread
From: Martin Krischik @ 2004-10-18  7:46 UTC (permalink / raw)


Hans Van den Eynden wrote:

> Hallo
> 
> I want to prevent that someone inherits from a type I made (for
> security purposes). I am a junior Ada programmer and I know this
> possible in Java (final class) and C# (sealed class). Is this also
> possible in Ada???

You could hide the tag:

package P

type T is private;

private

type T is tagged ...;

end P;

Of course it does not stop the determinted - since Ada private is C++
protected.

With Regards

Martin

-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-10-18  7:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1c2f5137.0410130438.3ea08553@posting.google.com>
2004-10-13 13:31 ` ada and final/sealed classes Dmitry A. Kazakov
2004-10-17 15:36 ` Matthew Heaney
2004-10-18  0:20   ` Brian May
2004-10-18  7:46 ` Martin Krischik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox